Skip to content

Fix undefined names reported by Flake8/Ruff#2101

Merged
Avasam merged 12 commits intomhammond:mainfrom
Avasam:undefined-names
Apr 9, 2024
Merged

Fix undefined names reported by Flake8/Ruff#2101
Avasam merged 12 commits intomhammond:mainfrom
Avasam:undefined-names

Conversation

@Avasam
Copy link
Copy Markdown
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
Copy Markdown
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)

if len(sys.argv) > 1:
docName = win32api.GetFullPathName(sys.argv[1])
OleTemplate().OpenDocumentFile(None)
OleTemplate().OpenDocumentFile(docName)
Copy link
Copy Markdown
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)

Avasam added 2 commits August 11, 2023 11:51
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
Comment thread com/win32com/server/exception.py Outdated
Comment thread com/win32comext/axdebug/Test/host.py Outdated
raise Exception(scode=winerror.E_NOTIMPL)


def TestSmartHelper():
Copy link
Copy Markdown
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.

Comment thread com/win32comext/axdebug/Test/host.py Outdated
Comment thread com/win32comext/axdebug/Test/host.py
Comment thread com/win32comext/axdebug/codecontainer.py Outdated
Comment thread com/win32comext/axdebug/codecontainer.py Outdated
@@ -1,23 +1,5 @@
# Generated by h2py from Include\scintilla.h
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread win32/Lib/mmsystem.py
Copy link
Copy Markdown
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!

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