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

TYP: use from __future__ import annotations more - batch 1 #41892

Merged
merged 2 commits into from
Jun 9, 2021

Conversation

simonjayhawkins
Copy link
Member

I'm fairly sure that we agreed we would do this but leave it to just before the 1.3 release to reduce the chance of auto backports failing

@simonjayhawkins simonjayhawkins added the Typing type annotations, mypy/pyright type checking label Jun 9, 2021
@simonjayhawkins simonjayhawkins added this to the 1.3 milestone Jun 9, 2021
@jreback
Copy link
Contributor

jreback commented Jun 9, 2021

after you have changed everything should create a rule to avoid Optional if this is possible.

@simonjayhawkins
Copy link
Member Author

after you have changed everything should create a rule to avoid Optional if this is possible.

it is still needed when creating aliases although I could move all aliases definitions into if TYPE_CHECKING blocks or into pandas._typing where that makes sense.

A couple of other points that have arisen from this exercise..
we are using Optional/Union alot in docstrings
some imports from pandas._typing instead of typing... could maybe limit what's reexported from pandas._typing.

@simonjayhawkins
Copy link
Member Author

I think is we have a rule that if we import from typing we also use from __future__ import annotations and pyupgrade and flake8 should make sure that the typing imports of Union, Optional etc are only used in casts and aliases.

@MarcoGorelli
Copy link
Member

I think is we have a rule that if we import from typing we also use from __future__ import annotations and pyupgrade and flake8 should make sure that the typing imports of Union, Optional etc are only used in casts and aliases.

Might be easier to require that every file (except for init.py , api.py, tests, setup.py, and probably just a handful of others) contains this import. This could be done with pygrep and --negate, I'll open an issue for this

@simonjayhawkins
Copy link
Member Author

sounds good

@jreback
Copy link
Contributor

jreback commented Jun 9, 2021

can you rebase thisone

@jreback jreback merged commit ce3bac9 into pandas-dev:master Jun 9, 2021
@mwaskom
Copy link
Contributor

mwaskom commented Jun 9, 2021

after you have changed everything should create a rule to avoid Optional if this is possible.

Sorry for barging in but can someone link me to context for this? My understanding was that the recommendation is to prefer Optional over a union with None (but maybe that changed with support for the | operator in type hints?)

@MarcoGorelli
Copy link
Member

@mwaskom yeah it's just to use the latest | None syntax, rather than anything against Optional specifically

@simonjayhawkins simonjayhawkins deleted the future-1 branch June 10, 2021 11:58
ForestMars added a commit to ForestMars/pandas that referenced this pull request Jun 11, 2021
ForestMars added a commit to ForestMars/pandas that referenced this pull request Jun 11, 2021
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants