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

Class Stock

Solutions/6_5/validate.py:84–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82 add = ValidatedFunction(add)
83
84 class Stock:
85 name = NonEmptyString()
86 shares = PositiveInteger()
87 price = PositiveFloat()
88 def __init__(self, name, shares, price):
89 self.name = name
90 self.shares = shares
91 self.price = price
92
93 def __repr__(self):
94 return f'Stock({self.name!r}, {self.shares!r}, {self.price!r})'
95
96 @property
97 def cost(self):
98 return self.shares * self.price
99
100 def sell(self, nshares):
101 self.shares -= nshares
102
103 sell = ValidatedFunction(sell) # Broken
104
105
106

Callers

nothing calls this directly

Calls 4

ValidatedFunctionClass · 0.85
NonEmptyStringClass · 0.70
PositiveIntegerClass · 0.70
PositiveFloatClass · 0.70

Tested by

no test coverage detected