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

Class Stock

Solutions/7_2/validate.py:147–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

NonEmptyStringClass · 0.70
PositiveIntegerClass · 0.70
PositiveFloatClass · 0.70

Tested by

no test coverage detected