Introspection: make __new__ return Self - #6384
Conversation
3aa01b0 to
745e70e
Compare
|
I think I'd prefer to simplify the macro code and instead make the import path determined by |
| const ITER_NEXT_OUTPUT: StaticIdent = StaticIdent::new("IterNextOutput"); | ||
| const ITER_NEXT_TYPE_FALLBACK: StaticIdent = StaticIdent::new("IterNextTypeFallback"); | ||
| const ASYNC_ITER_NEXT_OUTPUT: StaticIdent = StaticIdent::new("AsyncIterNextOutput"); | ||
| const ASYNC_ITER_NEXT_TYPE_FALLBACK: StaticIdent = StaticIdent::new("AsyncIterNextTypeFallback"); |
There was a problem hiding this comment.
These constants are actually also used in pymethod.rs, should we instead use one common declaration and import them into both usage sites?
There was a problem hiding this comment.
It's not exactly the same constants (IterNextTypeFallback vs AsyncIterNextConvertFallback). I can share the IterNextOutput and AsyncIterNextOutput if you want (it feels a bit overfitting DRY imho)
There was a problem hiding this comment.
I guess this is a great example of the version compatibility question, right? These are now stubs only supporting 3.11+, but these pytests only support 3.9+. So we should build stubs with Python 3.9?
There was a problem hiding this comment.
Yes! I am not sure we need them to be compatible with 3.9 for now, they are currently only used as a target for the test-introspection tests (checking that the stub generation output is the same as the provided stubs) and for mypy and pyrefly checks. So, we can just pick a version and stick with it. I just updated this MR to use 3.14 but glad to target 3.9 or 3.10 instead.
It a class is overridden but not __new__, __new__ still return an object instance of the child class and not of the parent class Uses typing.Self if the module is compiled for 3.11+, typing_extensions instead
It a class is overridden but not
__new__,__new__still return an object instance of the child class and not of the parent classUses
typing.Selfif the module is compiled for 3.11+,typing_extensions.Selfif notBased on #6362, it seems that
typing_extensionsis working for major type checkers even if not installed