FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Correct type annotations on two fields in _Arguments that are optional but are not marked as such by sam-xif · Pull Request #16897 · python/mypy · GitHub

Repository navigation

Correct type annotations on two fields in _Arguments that are optional but are not marked as such - #16897

Merged
hauntsaninja merged 3 commits into
python:masterfrom
sam-xif:_arguments-type-annotation-fixes
Feb 11, 2024
Merged

hauntsaninja merged 3 commits into
python:masterfrom
sam-xif:_arguments-type-annotation-fixes

Conversation

sam-xif commented Feb 9, 2024 •
edited
Loading

Copy link
Copy Markdown
Contributor

Hello mypy team,

I am working as part of a research team developing a code analysis tool for Python. One of the issues the tool discovered in mypy's codebase is that two fields in the _Arguments class, mypy_config_file and custom_typeshed_dir, can take on a None value, but they are not marked as such. Calling stubtest.parse_options on an empty list of arguments reproduces the situation where these two fields are None.

If you are interested in learning more about the tool and how it found this issue, let me know down in the comments, or you can contact me at xifaras.s@northeastern.edu. If you find that this issue is not legitimate, I would be interested in understanding why.

Note that I did not add any test cases as no functional changes to the code were made.

Thank you for your consideration!

-Sam

cdce8p left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The change looks correct. The code already handles the None case, so it's not an issue in reality. Nevertheless good to change it.

Just to satisfy the typing, could you adjust the abspath call a few lines below?

mypy/mypy/stubtest.py

Lines 1923 to 1925 in 517f5ae

options.custom_typeshed_dir = args.custom_typeshed_dir
if options.custom_typeshed_dir:
options.abs_custom_typeshed_dir = os.path.abspath(args.custom_typeshed_dir)

     if options.custom_typeshed_dir:
-        options.abs_custom_typeshed_dir = os.path.abspath(args.custom_typeshed_dir)
+        options.abs_custom_typeshed_dir = os.path.abspath(options.custom_typeshed_dir)

sam-xif commented Feb 9, 2024 •
edited
Loading

Copy link
Copy Markdown
Contributor Author

@cdce8p just saw your comment right after I pushed a change to resolve the type error. Instead of making the change you suggested, I changed the if condition to check if args.custom_typeshed_dir is truthy. I believe they are equivalent, but do you have a preference?

cdce8p commented Feb 9, 2024

Copy link
Copy Markdown
Collaborator

I would suggest to use the value from options. That better matches what we do for other values too. Directly below for mypy_config_file. We assign it to options.config_file and just use that afterwards.

mypy/mypy/stubtest.py

Lines 1926 to 1929 in 517f5ae

options.config_file = args.mypy_config_file
options.use_builtins_fixtures = use_builtins_fixtures
if options.config_file:

sam-xif commented Feb 9, 2024

Copy link
Copy Markdown
Contributor Author

@cdce8p Makes sense, thanks. Made the change you suggested.

cdce8p left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM! Thanks @sam-xif 👍🏻

Copy link
Copy Markdown
Collaborator

Thanks!

hauntsaninja merged commit 837f7e0 into python:master Feb 11, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

4 participants


Back | FazBrowse Home | New Git URL