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 undefined names reported by Flake8/Ruff #2101

Merged
merged 12 commits into from
Apr 9, 2024

Conversation

Avasam
Copy link
Collaborator

@Avasam Avasam commented Aug 10, 2023

These were found by running ruff . --select=F821 --exclude=build --exclude=Pythonwin/Scintilla --exclude=adodbapi
Closes #1994 by obsoleting it. @kxrob has been made co-author of this PR in the first commit. This PR is very similar to #1994, but with the following differences:

"Microsoft Word version 8 does not appear to be installed."
)

# WordModule.Word doesn't exist in WordModule, WordModule.Words does, but CreateControl still fails
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could either leave this as-is if we'd like to fix it later (the calling code is still commented out, at least now tooling won't report undefined names / unbound variables).

Or delete the WordFrame class entirely (doesn't look like this part of the demo was ever run in the git history)

@@ -142,11 +150,12 @@ def Demo():
docName = None
if len(sys.argv) > 1:
docName = win32api.GetFullPathName(sys.argv[1])
OleTemplate().OpenDocumentFile(None)
OleTemplate().OpenDocumentFile(docName)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That or remove the option to provide docName (which was unused)

Remove invalid self-referencing
Remove unused and unusable tests
Remove leftover casts from transpilation from c header
@Avasam Avasam changed the title Fix plenty of undefined names Fix undefined names reported by Flake8/Ruff Aug 11, 2023

def NotifyChanged():
trace("NotifyChanged")
raise Exception(scode=winerror.E_NOTIMPL)


def TestSmartHelper():
Copy link
Collaborator Author

@Avasam Avasam Aug 11, 2023

Choose a reason for hiding this comment

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

These were commented out in the caller code (so it's unused) and contain a bunch of undefined names / unbound variables.
If you still think it's worth keeping around, I'll comment them out instead.

@@ -1,23 +1,5 @@
# Generated by h2py from Include\scintilla.h
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd be curious in how to regenerate this file. It could give more insights on why there's undefined names here.

Copy link
Owner

Choose a reason for hiding this comment

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

There used to be a "h2py.py" file which came with Python - I've no idea if it still does, or if not, what happened to it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed in Python 3.9
Original issue: https://bugs.python.org/issue37704
GitHub issue: python/cpython#81885
GitHub PR: python/cpython#15000
Last version of the script before removal (no new commits between the 3.8 and 3.9 tag, other than removal): https://github.com/python/cpython/blob/3.8/Tools/scripts/h2py.py

Copy link
Collaborator Author

@Avasam Avasam Feb 8, 2024

Choose a reason for hiding this comment

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

Alright so, long story short: These "undefined names" in files generated by h2py have always been like this (meaning broken and unusable) so removing them doesn't hurt.

They are generated like that because h2py does string manipulation on c header files, then tries to evaluate the statements. Methods can successfully be defined in python even if the symbol doesn't exists (lazy evalution), so these get added to the generated python file.
The "undefined names" are mostly C casts or other C macros.


For posterity: Some files I've been able to regenerate nearly seamlessly (other than the manual stuff added), some are even improved, others are a complete mess.

Copy link
Owner

@mhammond mhammond left a comment

Choose a reason for hiding this comment

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

Thanks!

@Avasam Avasam merged commit cef71aa into mhammond:main Apr 9, 2024
27 checks passed
@Avasam Avasam deleted the undefined-names branch April 9, 2024 23:42
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