-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
mypy: run pyupgrade #12711
Conversation
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
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this 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') |
There was a problem hiding this comment.
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 {}
)
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
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, |
There was a problem hiding this comment.
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} ' + |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Jelle Zijlstra <[email protected]> Co-authored-by: Alex Waygood <[email protected]>
There was a problem hiding this 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.
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
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