MCPcopy Create free account
hub / github.com/dabeaz-course/python-mastery / Stock

Class Stock

Solutions/8_1/validate.py:151–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

149 return x - y
150
151 class Stock:
152 name = NonEmptyString()
153 shares = PositiveInteger()
154 price = PositiveFloat()
155 def __init__(self, name, shares, price):
156 self.name = name
157 self.shares = shares
158 self.price = price
159
160 def __repr__(self):
161 return f'Stock({self.name!r}, {self.shares!r}, {self.price!r})'
162
163 @property
164 def cost(self):
165 return self.shares * self.price
166
167 @validated
168 def sell(self, nshares:PositiveInteger):
169 self.shares -= nshares
170
171
172

Callers

nothing calls this directly

Calls 3

NonEmptyStringClass · 0.70
PositiveIntegerClass · 0.70
PositiveFloatClass · 0.70

Tested by

no test coverage detected