Introspection: generate nested classes for complex enums#5708
Introspection: generate nested classes for complex enums#5708davidhewitt merged 2 commits intoPyO3:mainfrom
Conversation
| /// Identifier of the class Rust struct | ||
| cls_ident: &'a Ident, | ||
| /// Name of the class in Python | ||
| cls_name: &'a Ident, |
There was a problem hiding this comment.
We need the two "flavors" because for complex enum variants the first one will be Enum_Variant and the second one just Variant
2b185a2 to
d49ade6
Compare
|
Note the the |
pytests/stubs/enums.pyi
Outdated
| class MixedComplexEnum: | ||
| @final | ||
| class Empty(MixedComplexEnum): ... | ||
|
|
||
| @final | ||
| class Nothing(MixedComplexEnum): ... |
There was a problem hiding this comment.
This syntax technically isn't valid:
class MixedComplexEnum:
@final
class Empty(MixedComplexEnum): ...
@final
class Nothing(MixedComplexEnum): ...gives
Traceback (most recent call last):
File "<python-input-2>", line 1, in <module>
class MixedComplexEnum:
...<4 lines>...
class Nothing(MixedComplexEnum): ...
File "<python-input-2>", line 3, in MixedComplexEnum
class Empty(MixedComplexEnum): ...
^^^^^^^^^^^^^^^^
NameError: name 'MixedComplexEnum' is not defined
... I wonder, is something like the below better?
class MixedComplexEnum:
Empty: Final[type[Empty]] = ...
Nothing: Final[type[Nothing]] = ...
@final
class Empty(MixedComplexEnum): ...
@final
class Nothing(MixedComplexEnum): ...There was a problem hiding this comment.
Interesting. Missed that. Thanks!
... I wonder, is something like the below better?
We would need to tweak it a bit to make sure Empty is not exposed as one of the member of the module. Happily there is a hack for that. I will experiment around it.
There was a problem hiding this comment.
I just tested with Mypy and this syntax error does not prevent it to parse the stubs.
I added the implementation of enums method to this MR.
If it's fine with you I would leave this issue for later (adding it to the introspection TODO issue) and focus on having mypy green on the pytests module (we are nearly there, with this MR and #5758 I only get misc and override errors that should be not too hard to fix). WDYT?
There was a problem hiding this comment.
Makes sense to me, happy to defer until when we know it's actually a problem (if it ever is).
d49ade6 to
0386177
Compare
No description provided.