3 ms·
:-) >>> class Money: ... def __init__(self, currency, amount): ... self.m = Counter({currency: amount}) ... def __add__(self, other):
by CraigJPerry 6y ago
:-)
>>> class Money:
... def __init__(self, currency, amount):
... self.m = Counter({currency: amount})
... def __add__(self, other):
... self.m += other.m
...
>>> Money("USD", 10) + Money(10, "EUR”)
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "<string>", line 5, in __add__
File "/var/containers/Bundle/Application/F8EBA093-47B6-4538-A3A5-553C9C2234FA/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/collections/__init__.py", line 805, in __iadd__
self[elem] += count
TypeError: unsupported operand type(s) for +=: 'int' and 'str'
Even Python yells at me for that.
In all seriousness though, how far do such mistakes survive? Not past compile here, but in other cases it could. Could it pass tests? Unlikely. Could it pass casually running the code, not impossible but again seems unlikely.
How many PRs on Github for projects written in dynamically typed languages are things that would be caught by static types? Some, it’s non-zero, it’s not anywhere close to a significant proportion though.