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

Class Stock

Solutions/7_1/validate.py:109–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107 return x / y
108
109 class Stock:
110 name = NonEmptyString()
111 shares = PositiveInteger()
112 price = PositiveFloat()
113 def __init__(self, name, shares, price):
114 self.name = name
115 self.shares = shares
116 self.price = price
117
118 def __repr__(self):
119 return f'Stock({self.name!r}, {self.shares!r}, {self.price!r})'
120
121 @property
122 def cost(self):
123 return self.shares * self.price
124
125 @validated
126 def sell(self, nshares:PositiveInteger):
127 self.shares -= nshares
128
129
130

Callers

nothing calls this directly

Calls 3

NonEmptyStringClass · 0.70
PositiveIntegerClass · 0.70
PositiveFloatClass · 0.70

Tested by

no test coverage detected