Skip to content

mypy: run pyupgrade #12711

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

Merged
merged 6 commits into from
May 1, 2022
Merged

mypy: run pyupgrade #12711

merged 6 commits into from
May 1, 2022

Conversation

hauntsaninja
Copy link
Collaborator

Re-attempt of #10741
Ran: pyupgrade --py36-plus $(fd -e py) --keep-runtime-typing
I mostly only needed to change things where NamedTuple comments got
dropped.
Notably, I omitted changes to pyinfo.py

Re-attempt of python#10741
Ran: `pyupgrade --py36-plus $(fd -e py) --keep-runtime-typing`
I mostly only needed to change things where NamedTuple comments got
dropped.
Notably, I omitted changes to pyinfo.py
@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@hauntsaninja hauntsaninja marked this pull request as draft May 1, 2022 19:59
Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

Only read up to lookup.py

@@ -214,7 +214,7 @@ def parse_config_file(options: Options, set_strict_flags: Callable[[], None],
print("%s: No [mypy] section in config file" % file_read, file=stderr)
else:
section = parser['mypy']
prefix = '%s: [%s]: ' % (file_read, 'mypy')
prefix = '{}: [{}]: '.format(file_read, 'mypy')
Copy link
Member

Choose a reason for hiding this comment

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

Again (and need to make sure we simplify away the second {})

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

elif major == 3:
if minor < defaults.PYTHON3_VERSION_MIN[1]:
raise argparse.ArgumentTypeError(
"Python 3.{0} is not supported (must be {1}.{2} or higher)".format(minor,
"Python 3.{} is not supported (must be {}.{} or higher)".format(minor,
Copy link
Member

Choose a reason for hiding this comment

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

I think it might be cleaner to unpack PYTHON3_VERSION_MIN in the previous line and then use an f-string here

@@ -1113,7 +1113,7 @@ def overloaded_signature_will_never_match(self, index1: int, index2: int,
context)

def overloaded_signatures_typevar_specific(self, index: int, context: Context) -> None:
self.fail('Overloaded function implementation cannot satisfy signature {} '.format(index) +
self.fail(f'Overloaded function implementation cannot satisfy signature {index} ' +
Copy link
Member

Choose a reason for hiding this comment

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

It might be nice to make this line PEP8-compliant by moving the + at the end of the line to the beginning of the next line

Copy link
Member

Choose a reason for hiding this comment

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

We should merge the PR that Blackens mypy so we don't have to worry about this.

Copy link
Member

Choose a reason for hiding this comment

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

That too :)

@@ -113,7 +117,7 @@ def __init__(self, path: Optional[str], module: Optional[str],
self.base_dir = base_dir # Directory where the package is rooted (e.g. 'xxx/yyy')

def __repr__(self) -> str:
return 'BuildSource(path=%r, module=%r, has_text=%s, base_dir=%r)' % (
return 'BuildSource(path={!r}, module={!r}, has_text={}, base_dir={!r})'.format(
Copy link
Member

Choose a reason for hiding this comment

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

Could be an f-string

Copy link
Member

Choose a reason for hiding this comment

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

(There are still several others I noticed as well)

@github-actions

This comment has been minimized.

Co-authored-by: Jelle Zijlstra <[email protected]>
Co-authored-by: Alex Waygood <[email protected]>
Copy link
Collaborator Author

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

I've committed the suggestions, but I think we should merge this approximately as is and make further changes in other PRs — especially so for manual changes.
There are many .format that pyupgrade doesn't get and I'll maybe play with other approaches for porting those. And +1 to leaving black things to black.

@github-actions
Copy link
Contributor

github-actions bot commented May 1, 2022

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@hauntsaninja hauntsaninja marked this pull request as ready for review May 1, 2022 21:52
@hauntsaninja hauntsaninja merged commit fc335cb into python:master May 1, 2022
@hauntsaninja hauntsaninja deleted the pyupgr4 branch May 1, 2022 21:52
ikonst added a commit to ikonst/mypy that referenced this pull request Jul 12, 2023
JelleZijlstra pushed a commit that referenced this pull request Jul 12, 2023
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.

3 participants