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

CI: Upgrade 'pyupgrade' (v2.7.4 --> v2.9.0) #39538

Merged
merged 1 commit into from
Feb 3, 2021

Conversation

gunjan-solanki
Copy link
Contributor


This PR upgrades pyupgrade and also includes style/formatting changes required after upgrading pyupgrade, namely, removing unused imports (flake8), and running black and isort.

@simonjayhawkins simonjayhawkins added the Code Style Code style, linting, code_checks label Feb 1, 2021
@simonjayhawkins simonjayhawkins added this to the 1.3 milestone Feb 1, 2021
@gunjan-solanki gunjan-solanki marked this pull request as draft February 1, 2021 18:52
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Thanks @gunjan-solanki for doing this

@simonjayhawkins @Dr-Irv are we OK with making these PEP604 changes? I just saw that an issue was raised here asottile/pyupgrade#387 (comment) , I don't know if that applies to pandas (I haven't yet looked into "runtime introspection of type hints" and don't know if it's a concern which applies)

If we didn't want these rewrites, we could pass --keep-runtime-typing to pyupgrade

@gunjan-solanki
Copy link
Contributor Author

gunjan-solanki commented Feb 1, 2021

I converted it to draft because of failing typing validation. Few other tests are also failing, possibly because I used autoflake to remove unused imports and it also ended up removing pass statements. Although I am not sure about the exact cause (Could be because of PEP604 issue @MarcoGorelli mentioned).
Will investigate further and push the fix.

@Dr-Irv
Copy link
Contributor

Dr-Irv commented Feb 1, 2021

@simonjayhawkins @Dr-Irv are we OK with making these PEP604 changes? I just saw that an issue was raised here asottile/pyupgrade#387 (comment) , I don't know if that applies to pandas (I haven't yet looked into "runtime introspection of type hints" and don't know if it's a concern which applies)

I'm not 100% sure here, but it seems that we don't want all these typing changes to happen because it would then break doing mypy checks in a Python 3.7, 3.8 and even 3.9 environment. E.g., the Union[x,y] to x | y is in Python 3.10, and that syntax wouldn't be supported in earlier versions.

So using --keep-runtime-typing on pyupgrade is probably a better way to go, IMHO.

@simonjayhawkins
Copy link
Member

I don't think runtime introspection is an issue. I'm generally happy with these changes. This sort of change where changes are made across the codebase can cause autobackports to fail and we don't want to backport style changes. But we will need to take that hit a some point, so no reason imo not to do it sooner rather than later.

@MarcoGorelli
Copy link
Member

E.g., the Union[x,y] to x | y is in Python 3.10, and that syntax wouldn't be supported in earlier versions.

Isn't it supported as long as you have from __future__ import annotations?

@MarcoGorelli
Copy link
Member

I converted it to draft because of failing typing validation. Few other tests are also failing, possibly because I used autoflake to remove unused imports and it also ended up removing pass statements. Although I am not sure about the exact cause (Could be because of PEP604 issue @MarcoGorelli mentioned).
Will investigate further and push the fix.

There's a number of CI error ATM so these may be unrelated, will come back to this when CI's fixed

@Dr-Irv
Copy link
Contributor

Dr-Irv commented Feb 1, 2021

Isn't it supported as long as you have from __future__ import annotations?

Maybe. I guess we would have to test it in different python versions to be sure. My concern with this typing stuff is that if our library goes out with the latest PEP typing enhancements, and then someone is using python 3.7 and a version of mypy on their application, whether everything will work properly. I think we should stick to "least common denominator" on typing things, but I could be convinced otherwise.

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

definitely ok with the idea here. but is this syntax backwards compatible to 1.2.2 if we need to backport things?

e.g. we have a lower mypy version in 1.2.2

@MarcoGorelli
Copy link
Member

That's a good point - maybe this should wait until 1.4.0 then, so that 1.3.x would have a modern enough version of mypy?

@gunjan-solanki
Copy link
Contributor Author

How should I proceed?

  • Should I close the PR for the time being? or
  • Update the PR to pass --keep-runtime-typing to pyupgrade ?

Thanks!

@MarcoGorelli
Copy link
Member

@gunjan-solanki based on the above (which I hadn't considered when I opened the issue, sorry!), I think we can go with the latter, i.e.

-   repo: https://github.com/asottile/pyupgrade
    rev: v2.9.0
    hooks:
    -   id: pyupgrade
        args: [--py37-plus, --keep-runtime-typing]

This argument can be removed when 1.3.0 is out and autobackports will be a bit easier

If you do

git checkout upstream/master -- .

and then make the above changes to .pre-commit-config.yaml, then I think pre-commit run pyupgrade -a should pass without it reformatting anything (so, the diff should only show .pre-commit-config.yaml)

@gunjan-solanki
Copy link
Contributor Author

gunjan-solanki commented Feb 3, 2021

and then make the above changes to .pre-commit-config.yaml, then I think pre-commit run pyupgrade -a should pass without it reformatting anything (so, the diff should only show .pre-commit-config.yaml)

@MarcoGorelli Your guess is spot on. I tested it yesterday and can confirm no reformatting is necessary.

@gunjan-solanki based on the above (which I hadn't considered when I opened the issue, sorry!), I think we can go with the latter, i.e.

Not an issue. Happy to help. I will go ahead and update the PR :)

Resolves: GH39523

This commit also adds '--keep-runtime-typing' flag to pyupgrade
because of issue with runtime introspection of type hints and backwards
compatiblity with v1.2.2.

This flag can be removed when v1.3.0 is out and autobackports
is a bit easier
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

@gunjan-solanki gunjan-solanki marked this pull request as ready for review February 3, 2021 15:39
@MarcoGorelli MarcoGorelli merged commit dae99c7 into pandas-dev:master Feb 3, 2021
@gunjan-solanki gunjan-solanki deleted the upgrade-pyupgrade branch February 3, 2021 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CI upgrade pyupgrade
5 participants