Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tools.codegenerator for NameError and AttributeError in generated modules. #294

Merged
merged 3 commits into from
May 29, 2022

Conversation

junkmd
Copy link
Collaborator

@junkmd junkmd commented May 29, 2022

#293

Fix NameError and AttributeError in generated modules.

Relationship with #287

I PRed #287 to fix lack of from ctypes import * line in generated modules(#284).
But another problem in namespaces of generated modules(#293).
This PR fixes both problems.

Note for changes

Add ImportedNamespaces and DeclaredNamespaces

They will be Generator attribute instead of dict or io.StringIO.
Formerly, to avoid duplicating import and alias-declaring lines, Generator._Foo_defined attributes are necessary.
With this change, ImportedNamespaces and DeclaredNamespaces prevent duplication of generated modules' lines instead of Generator itself.

self.output is used only when Generator.generate_code was called

Formerly, many I/O(self.output, self.declarations, self.stream) and writing/printing to them are messy and will be a root of weird bugs.
With this change, self.stream is the I/O that will be mainly used and self.output is used only in Generator.generate_code.

from collections import OrderedDict
self.data = OrderedDict()

def add(self, *names, symbols=None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This syntax (*names and further keyword args) is not Py2.7 compatible. I still want to keep it for pywinauto project.

Copy link
Collaborator Author

@junkmd junkmd May 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vasily-v-ryabov

I made this py27-compatible.

P.S.
*names, symbols=None syntax was not failed in AppVeyor CI.
Perhaps, some tests are broken.

IMO release of 1.1.13 should wait until tests were fixed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comtypes AppVeyor tests are very limited. There are only 2 install tests. The vast majority of functional tests are not enabled in AppVeyor for now. I've detected this Py2.7 issue on pywinauto tests (on pywinauto's AppVeyior). If they pass, I'm probably going to merge this PR. Thanks for your efforts!

@junkmd
Copy link
Collaborator Author

junkmd commented May 29, 2022

I fixed class name case(DeclaredNameSpaces -> DeclaredNamespaces, adjusted as ImportedNamespaces).

@junkmd junkmd requested a review from vasily-v-ryabov May 29, 2022 11:19
@vasily-v-ryabov vasily-v-ryabov merged commit fc7cc0a into enthought:master May 29, 2022
@junkmd junkmd deleted the fix_codegenerator_namespaces branch May 30, 2022 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants