makepy: support for enums and type-hints#1364
makepy: support for enums and type-hints#1364tobias-loew wants to merge 11 commits intomhammond:masterfrom
Conversation
Hi, I've added command flags to generate enum and type-hints. I've tested it with a quite large typelib (generated py-file has > 100k lines) and it seems to work. Regarding the enums: there's also code for creating "Enums" (instead of "IntEnums"; use createEnums == 1) but a could find a way to make properties working without either putting a runtime penalty on everyone or breaking the ABI in __init__.py. Maybe you've got an idea! Tobias
|
Hello @tobias-loew ! Can you tell us which typelib has been used to test your work? Work be great to know to be able to reproduce your work. Thanks! 🙂 |
|
Hi, |
mhammond
left a comment
There was a problem hiding this comment.
Sorry for the delay. Can you please give some examples of the output this generates? It's difficult to read given all the 2to3 changes here, which I'd prefer to not be part of this patch (although I really should make python 2.7 compatible changes to the entire tree)
removed unused option from command line help
removed unused option from command line help
|
I've import the "Microsoft Scripting Runtime" three times: the old way, with enums and with enums & typehints. And here is the imported "with enums and typehints" version of EbsOpen.py (the product I develop) |
|
The extension for enums and type-hints require Python 3. So, all changes here target only Python 3. |
|
@tobias-loew to hide code from Python 2 use: @mhammond given that version 300 was just released, the problems with 2to3 changes should be resolved or? |
Yes, please! |
|
I've resolved the conflicts but didn't yet have time to make the "sys.version_info >= (3, 0)" changes. |
|
IMHO the best way is to add an additional option to support the generation of files with enums for version 3 AND the old style for version 2. |
|
Python 2 is not supported anymore. You can drop any Python 2 code. |
Thats because of the deprecated "::set-env" command in the github CI runner - since 2 weeks or so. A fix is already in #1622 (patch |
|
I made a local branch with the setenv-fix: all tests (but one that seems to hang) passed (https://github.com/tobias-loew/pywin32/actions/runs/390146137) |
mhammond
left a comment
There was a problem hiding this comment.
I had a quick look as I'm very busy at the moment, so might take some time to get back to this. I can't even remember what's in the .zip file you attached previously, but I do note that this really needs some comments - eg, what exactly is an enum in this context? What is a type-hint? When would I want to enable those options? When would I not want to enable those options? How is the large NativeTypeMap object used, etc? Ideally we'd also have tests, maybe by abusing PyCOMTest.idl?
| @@ -0,0 +1,33 @@ | |||
| """Contains RelaxedIntEnum | |||
|
|
|||
| This module is used by modules build by @makepy@ using enums. | |||
| typename = "DispatchItem" | ||
|
|
||
| def __init__(self, typeinfo=None, attr=None, doc=None, bForUser=1): | ||
| def __init__(self, typeinfo=None, attr=None, doc=None, bForUser=1, iCreateEnums=0): |
There was a problem hiding this comment.
I'm not a huge fan of iCreateEnums - it looks everywhere like it's actually a bool, except in one place where magic values of 1 and 2 are used. ISTM an - err - enum would make sense here?
| return None | ||
|
|
||
| def BuildCallList(fdesc, names, defNamedOptArg, defNamedNotOptArg, defUnnamedArg, defOutArg, is_comment = False): | ||
| def BuildCallList(fdesc, names, defNamedOptArg, defNamedNotOptArg, defUnnamedArg, defOutArg, is_comment = False, bTypeHints = 0): |
There was a problem hiding this comment.
Please use False as the default.
|
Thanks for the contribution, and feel free to reopen this if you end up making the requested changes. |
|
Hi Mark, I've seen your currently working on the project, so let me pick up the pieces from 2 years ago and answer your questions:
I adopted my changes to the new best |
Hi,
I've added command flags to generate enum and type-hints.
I've tested it with a quite large typelib (generated py-file has > 100k lines) and it seems to work.
Regarding the enums: there's also code for creating "Enums" (instead of "IntEnums"; use createEnums == 1) but a could find a way to make properties working without either putting a runtime penalty on everyone or breaking the ABI in init.py. Maybe you've got an idea!
Tobias