CrossHair icon indicating copy to clipboard operation
CrossHair copied to clipboard

Extending native types doesn't work as expected

Open pschanely opened this issue 3 years ago • 2 comments

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

pschanely avatar Nov 11 '22 17:11 pschanely

@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.

mristin avatar Nov 11 '22 17:11 mristin

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.

pschanely avatar Nov 11 '22 18:11 pschanely