-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TYP: Implicit generic "Any" for builtins #30541
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
….List" and specify generic parameters
… Use "typing.List" and specify generic parameters
…ing.Tuple" and specify generic parameters
…e "typing.Dict" and specify generic parameters
…c "Any". Use "typing.List" and specify generic parameters
…c "Any". Use "typing.List" and specify generic parameters
…g.List" and specify generic parameters
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.
lgtm, thanks!
pandas/_typing.py
Outdated
@@ -32,10 +33,12 @@ | |||
FilePathOrBuffer = Union[str, Path, IO[AnyStr]] | |||
|
|||
FrameOrSeries = TypeVar("FrameOrSeries", bound="NDFrame") | |||
Scalar = Union[str, int, float, bool] | |||
PythonScalar = Union[str, int, float, bool] |
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.
would move DatetimeLikeScalar closer to these (also would add some comments about various sections, e.g. these are Scalars )
pandas/core/common.py
Outdated
@@ -270,7 +270,10 @@ def maybe_make_list(obj): | |||
return obj | |||
|
|||
|
|||
def maybe_iterable_to_list(obj: Union[Iterable, Any]) -> Union[list, Any]: | |||
_T = TypeVar("_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.
should't we just do this in _typing (and just call it T)
DatetimeLikeScalar = TypeVar("DatetimeLikeScalar", "Period", "Timestamp", "Timedelta") | ||
PandasScalar = Union[DatetimeLikeScalar, "Interval"] | ||
Scalar = Union[PythonScalar, PandasScalar] |
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.
Does it matter that this is a Union of a Union and a TypeVar? Maybe DatetimeLikeScalar should just be a Union?
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, we have the same issue as with FilePathOrBuffer, where IO is unbound in the Union and requires the addition of type parameters when using the alias.
and we don't really want that for Scalar. but we had Scalar as a union (for JSONSerializable) and DatetimeLikeScalar as a TypeVar.
Maybe DatetimeLikeScalar should just be a Union?
rather than change this, maybe should define PandasScalar = Union["Period", "Timestamp", "Timedelta", "Interval"]
for now
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.
Yea makes sense
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.
lgtm. @WillAyd over to you
Is there a config setting to (dis)allow this per module? Or is it global? |
disallow_any_generics picks these up, see #30539, could be global or per module. To ONLY find these would require custom script/clever regex |
Gotcha. So we'll just need to watch out for these until #30539 is all done? |
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.
Lgtm. @TomAugsburger merge away whenever questions resolved
Thanks! |
Grr sorry I messed up the merge. Did a rebase and merge instead of a squash. Sorry :/ |
xref #30539