Open pschanely opened 2 years ago
@pschanely thanks! Be aware that we used __new__
intensively to impose constraints on primitive types in https://github.com/mristin/python-by-contract. That was a "canonical" way for me, and also the efficient one as values can not be mutated.
Indeed; I recall some of that! In general, CrossHair should be able to construct via the signatures on __new__
and __init__
appropriately.
Even after construction, though, I expect some additional hurdles for classes extending some of the core types: str, list, dict, etc. Needs more investigation!
I believe many of the python-by-contract classes were never actually instantiated - that is, the __new__
just returned its argument. Those cases hopefully aren't subject to such challenges.
As shown in this example, extending native types (that CrossHair cares about) doesn't work as expected.
I suspect there may be multiple layers of problems, the first of which is that a correct constructor signature is harder to deduce for these types.
cc @mristin