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

Class Stock

Solutions/7_4/validate.py:145–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

NonEmptyStringClass · 0.70
PositiveIntegerClass · 0.70
PositiveFloatClass · 0.70

Tested by

no test coverage detected