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

Class Stock

Solutions/7_3/validate.py:146–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

NonEmptyStringClass · 0.70
PositiveIntegerClass · 0.70
PositiveFloatClass · 0.70

Tested by

no test coverage detected