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

TYPING: check-untyped-defs for util._decorators #28128

Merged
merged 1 commit into from
Aug 27, 2019

Conversation

simonjayhawkins
Copy link
Member

@simonjayhawkins simonjayhawkins commented Aug 24, 2019

$ mypy pandas/util/_decorators.py --check-untyped-defs --follow-imports skip
pandas\util\_decorators.py:181: error: Item "function" of "Union[Dict[Any, Any], Callable[[Any], Any]]" has no attribute "get"
pandas\util\_decorators.py:183: error: "Dict[Any, Any]" not callable
pandas\util\_decorators.py:201: error: Argument 1 to "get" of "Mapping" has incompatible type "Optional[str]"; expected "str"
pandas\util\_decorators.py:207: error: Invalid index type "Optional[str]" for "Dict[str, Any]"; expected type "str"
pandas\util\_decorators.py:293: error: Item "Tuple[Any, ...]" of "Union[Tuple[Any, ...], Dict[str, Any]]" has no attribute "update"
$ mypy pandas/util/_decorators.py --disallow-any-generics --follow-imports skip
pandas\util\_decorators.py:12: error: Missing type parameters for generic type
pandas\util\_decorators.py:18: error: Missing type parameters for generic type
pandas\util\_decorators.py:93: error: Missing type parameters for generic type
pandas\util\_decorators.py:95: error: Missing type parameters for generic type
pandas\util\_decorators.py:217: error: Missing type parameters for generic type
pandas\util\_decorators.py:282: error: Missing type parameters for generic type
pandas\util\_decorators.py:323: error: Missing type parameters for generic type

also fixes following errors arising from more precise typing...

pandas\core\indexes\interval.py:790: error: Signature of "get_loc" incompatible with supertype "Index"
pandas\core\indexes\interval.py:985: error: Too many arguments for "get_indexer_non_unique" of "IntervalIndex"
pandas\core\groupby\generic.py:889: error: Incompatible types in assignment (expression has type "Callable[[DefaultArg(Any, 'func_or_funcs'), VarArg(Any), KwArg(Any)], Any]", base class "SelectionMixin" defined the type as "Callable[[Arg(Any, 'func'), VarArg(Any), KwArg(Any)], Any]")
pandas\core\groupby\generic.py:1470: error: Incompatible types in assignment (expression has type "Callable[[DefaultArg(Any, 'arg'), VarArg(Any), KwArg(Any)], Any]", base class "NDFrameGroupBy" defined the type as "Callable[[Arg(Any, 'func'), VarArg(Any), KwArg(Any)], Any]")
pandas\core\window\rolling.py:913: error: Incompatible types in assignment (expression has type "Callable[[Arg(Any, 'arg'), VarArg(Any), KwArg(Any)], Any]", base class "_Window" defined the type as "Callable[[Arg(Any, 'func'), VarArg(Any), KwArg(Any)], Any]")
pandas\core\window\rolling.py:1794: error: Incompatible types in assignment (expression has type "Callable[[Arg(Any, 'arg'), VarArg(Any), KwArg(Any)], Any]", base class "_Window" defined the type as "Callable[[Arg(Any, 
'func'), VarArg(Any), KwArg(Any)], Any]")
pandas\core\window\expanding.py:142: error: Incompatible types in assignment (expression has type "Callable[[Arg(Any, 'arg'), VarArg(Any), KwArg(Any)], Any]", base class "_Window" defined the type as "Callable[[Arg(Any, 'func'), VarArg(Any), KwArg(Any)], Any]")
pandas\core\window\ewm.py:212: error: Incompatible types in assignment (expression has type "Callable[[Arg(Any, 'arg'), VarArg(Any), KwArg(Any)], Any]", base class "_Window" defined the type as "Callable[[Arg(Any, 'func'), VarArg(Any), KwArg(Any)], Any]")

@simonjayhawkins simonjayhawkins added the Typing type annotations, mypy/pyright type checking label Aug 24, 2019
pandas/util/_decorators.py Show resolved Hide resolved
@@ -90,9 +104,9 @@ def wrapper(*args, **kwargs):
def deprecate_kwarg(
old_arg_name: str,
new_arg_name: Optional[str],
mapping: Optional[Union[Dict, Callable[[Any], Any]]] = None,
mapping: Optional[Union[Dict[Any, Any], Callable[[Any], Any]]] = None,
Copy link
Member

Choose a reason for hiding this comment

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

I think OK just to do Dict instead of Dict[Any, Any]; same thing but more readable

Copy link
Member Author

Choose a reason for hiding this comment

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

it is the same thing but would fail --disallow-any-generics check.

although readability is important, i don't think the benefits of precise type checking can be understated.

pandas/core/indexes/interval.py Show resolved Hide resolved
@WillAyd WillAyd added this to the 1.0 milestone Aug 25, 2019
Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

lgtm. Merge in a day or two if no other feedback

@WillAyd
Copy link
Member

WillAyd commented Aug 27, 2019

This should also close #27404 - updated OP to reflect that

@WillAyd WillAyd merged commit bd8dbf9 into pandas-dev:master Aug 27, 2019
@WillAyd
Copy link
Member

WillAyd commented Aug 27, 2019

Thanks @simonjayhawkins

@simonjayhawkins simonjayhawkins deleted the util._decorators branch August 28, 2019 11:35
simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this pull request Sep 6, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
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.

Support Decorators Maintaining Signatures of Generic Functions
2 participants