-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
STY: remove --keep-runtime-typing from pyupgrade Part-1 #40773
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
Conversation
fathomer
commented
Apr 3, 2021
•
edited by MarcoGorelli
Loading
edited by MarcoGorelli
- xref STYLE remove --keep-runtime-typing from pyupgrade #40759
- tests added / passed
- Ensure all linting tests pass, see here for how to run them
- whatsnew entry
The mypy failures are due to the fact that some of these methods have their own method small example: # t.py
from __future__ import annotations
from typing import Type
class Cat:
def type(self) -> str:
return 'this is my type'
def type_cat(self) -> Type[Cat]:
return Cat works fine: $ mypy t.py
Success: no issues found in 1 source file but the following: # t.py
from __future__ import annotations
from typing import Type
class Cat:
def type(self) -> str:
return 'this is my type'
def type_cat(self) -> type[Cat]:
return Cat doesn't: $ mypy t.py
t.py:10: error: Function "t.Cat.type" is not valid as a type
t.py:10: note: Perhaps you need "Callable[...]" or a callback protocol?
Found 1 error in 1 file (checked 1 source file) If we moved the definitions around so that I think the solution here is to define the alias EDITActually, using $ mypy t.py
t.py:12: error: "type" expects no type arguments, but 1 given [type-arg]
Found 1 error in 1 file (checked 1 source file) will think of how to do this EDIT2This seems to work: in diff --git a/pandas/_typing.py b/pandas/_typing.py
index f90ef33434..c11cfc0f21 100644
--- a/pandas/_typing.py
+++ b/pandas/_typing.py
@@ -25,7 +25,7 @@ from typing import (
Optional,
Sequence,
diff --git a/pandas/_typing.py b/pandas/_typing.py
index f90ef33434..c11cfc0f21 100644
--- a/pandas/_typing.py
+++ b/pandas/_typing.py
@@ -25,7 +25,7 @@ from typing import (
Optional,
Sequence,
Tuple,
- Type,
+ Type as Type_t,
TypeVar,
Union,
)
@@ -119,7 +119,7 @@ Axes = Collection[Any]
# dtypes
NpDtype = Union[str, np.dtype]
Dtype = Union[
- "ExtensionDtype", NpDtype, Type[Union[str, float, int, complex, bool, object]]
+ "ExtensionDtype", NpDtype, Type_t[Union[str, float, int, complex, bool, object]]
]
# DtypeArg specifies all allowable dtypes in a functions its dtype argument
DtypeArg = Union[Dtype, Dict[Hashable, Dtype]]
@@ -187,3 +187,5 @@ ColspaceArgType = Union[
# internals
Manager = Union["ArrayManager", "BlockManager"]
SingleManager = Union["SingleArrayManager", "SingleBlockManager"] then for any of the lines that are throwing errors, in those files, import |
1235bee
to
274c8b5
Compare
Thanks @MarcoGorelli for the nice explanation and suggestion, I have made changes according to that and pushed my code. |
Nice, thanks @fathomer ! Let's wait to hear from the others 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.
this will get quickly out of date. i would rebase now and we'll see if cna merge it. but maybe better to break into pieces.
confirming this is basically List -> list, Dict -> dict, Tuple -> tuple (can you put the list in the top).
if its more complicated than that we should do in steps.
pandas/_typing.py
Outdated
@@ -25,7 +25,7 @@ | |||
Optional, | |||
Sequence, | |||
Tuple, | |||
Type, | |||
Type as Type_T, |
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.
why not TypeT
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.
or type_t ?
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.
you're right, type_t
would be more consistent
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.
So I will change the variable name to type_t, keep the changes to 15-20 files as of now, and still keep the --keep-runtime-typing flag there in precommit hook.
Is that right @MarcoGorelli ?
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.
yes, that's right @fathomer! Then, in the final PR, you can remove the flag
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 have reverted changes to all other files except some 20 files for this PR, did a rebase to upstream/master and pushed.
For the remaining files do you want me raise the other PRs just now or wait until this one gets merged ?
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.
Thanks @fathomer! You can raise the others now if you want, I'll look over them tomorrow
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.
@MarcoGorelli @jreback Raised the other PRs as well, for some reason not getting the option to add you guys as reviewers there. Please feel free to review them.
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.
Agree on breaking into smaller pieces - if you apply these changes to, say, 15-20 files at a time, then the current check will still pass even if it has --keep-runtime-typing
.
If you could break this into a few smaller pull requests, each with no more than 20 files, then we can get those in, and at the end, we can remove --keep-runtime-typing
Jeff - the changes here are from PEP585 (e.g. List[str]
-> list[str]
) and from PEP604 (Optional[str]
-> str | None
), both of which are only applied in the presence of from __future__ import annotations
f9212a1
to
db0aa16
Compare
Looks good, thanks! |