Gentlemen Agreement Type Hint
In [52]: @dataclass ...: class A: ...: x: int ...: y: str In [53]: a = A(1, 2) In [54]: type(a.x) Out[54]: int In [55]: type(a.y) Out[55]: int In [56]: # Gentlemen agreement
A Python dataclass declares `y` as a string, but the object is created with an integer and Python accepts it without enforcing the annotation. The joke is that type hints are merely a “gentlemen agreement” at runtime. EN: A Python dataclass declares `y` as a string, but the object is created with an integer and Python accepts it without enforcing the annotation. The joke is that type hints are merely a “gentlemen agreement” at runtime.
- @profunctor_io / 2575 2019-07-10
- Type
- image
- Size
- 286×282 · 14.3 KiB
- Mood
- ирonic
- Language
- en
- Added