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

Add py.typed #92

Merged
merged 1 commit into from
May 9, 2022
Merged

Add py.typed #92

merged 1 commit into from
May 9, 2022

Conversation

Illviljan
Copy link
Contributor

This should allow mypy to parse flox if it's being imported by for example xarray.

@dcherian
Copy link
Collaborator

dcherian commented May 9, 2022

Our current typing is not great. I stopped updating it 6 months ago. Shall we fix the typing before enabling?

@Illviljan
Copy link
Contributor Author

I added it locally so it appears to remove the errors left in pydata/xarray#5734 at least!
Looks to me you've done a good attempt so I don't think there's anything to hold off on. Might go faster finding the left over bugs with this active as well.

@dcherian
Copy link
Collaborator

dcherian commented May 9, 2022

There are a bunch of errors if I run mypy in flox/

A lot seem easy and some seem like bugs =)

flox/core.py:69: error: Value of type "Optional[Any]" is not indexable  [index]
flox/core.py:69: error: Argument "isbin" to "_convert_expected_groups_to_index" has incompatible type "Tuple[bool]"; expected "bool"  [arg-type]
flox/core.py:447: error: Value of type "Optional[ndarray[Any, Any]]" is not indexable  [index]
flox/core.py:550: error: Incompatible default for argument "axis" (default has type "None", argument has type "Union[int, Sequence[int]]")  [assignment]
flox/core.py:605: error: Incompatible types in assignment (expression has type "Tuple[None]", variable has type "Optional[Mapping[Union[str, Callable[..., Any]], Any]]")  [assignment]
flox/core.py:661: error: No overload variant of "zip" matches argument types "Union[Sequence[str], Sequence[Callable[..., Any]]]", "None", "Any", "Any"  [call-overload]
flox/core.py:661: note: Possible overload variants:
flox/core.py:661: note:     def [_T_co, _T1] zip(cls, Iterable[_T1]) -> zip[Tuple[_T1]]
flox/core.py:661: note:     def [_T_co, _T1, _T2] zip(cls, Iterable[_T1], Iterable[_T2]) -> zip[Tuple[_T1, _T2]]
flox/core.py:661: note:     def [_T_co, _T1, _T2, _T3] zip(cls, Iterable[_T1], Iterable[_T2], Iterable[_T3]) -> zip[Tuple[_T1, _T2, _T3]]
flox/core.py:661: note:     def [_T_co, _T1, _T2, _T3, _T4] zip(cls, Iterable[_T1], Iterable[_T2], Iterable[_T3], Iterable[_T4]) -> zip[Tuple[_T1, _T2, _T3, _T4]]
flox/core.py:661: note:     def [_T_co, _T1, _T2, _T3, _T4, _T5] zip(cls, Iterable[_T1], Iterable[_T2], Iterable[_T3], Iterable[_T4], Iterable[_T5]) -> zip[Tuple[_T1, _T2, _T3, _T4, _T5]]
flox/core.py:661: note:     def [_T_co] zip(cls, Iterable[Any], Iterable[Any], Iterable[Any], Iterable[Any], Iterable[Any], Iterable[Any], *iterables: Iterable[Any]) -> zip[Tuple[Any, ...]]
flox/core.py:665: error: Argument 1 to "is_nanlen" has incompatible type "None"; expected "Union[str, Callable[..., Any]]"  [arg-type]
flox/core.py:802: error: Unsupported left operand type for + ("Sequence[Any]")  [operator]
flox/core.py:804: error: Unsupported left operand type for + ("Sequence[Any]")  [operator]
flox/core.py:809: error: Incompatible return value type (got "Dict[str, Any]", expected "Dict[Union[str, Callable[..., Any]], Any]")  [return-value]
flox/core.py:809: note: Perhaps you need a type annotation for "results"? Suggestion: "Dict[Union[str, Callable[..., Any]], Any]"
flox/core.py:895: error: Incompatible types in assignment (expression has type "Dict[Union[str, Callable[..., Any]], Any]", variable has type "Dict[str, object]")  [assignment]
flox/core.py:911: error: "object" has no attribute "append"  [attr-defined]
flox/core.py:914: error: "object" has no attribute "append"  [attr-defined]
flox/core.py:921: error: Argument "fill_value" to "chunk_reduce" has incompatible type "Tuple[int]"; expected "Optional[Mapping[Union[str, Callable[..., Any]], Any]]"  [arg-type]
flox/core.py:937: error: "object" has no attribute "append"  [attr-defined]
flox/core.py:950: error: Argument "fill_value" to "chunk_reduce" has incompatible type "Tuple[Any]"; expected "Optional[Mapping[Union[str, Callable[..., Any]], Any]]"  [arg-type]
flox/core.py:955: error: "object" has no attribute "append"  [attr-defined]
flox/core.py:957: error: Incompatible return value type (got "Dict[str, object]", expected "Dict[Union[str, Callable[..., Any]], Any]")  [return-value]
flox/core.py:957: note: Perhaps you need a type annotation for "results"? Suggestion: "Dict[Union[str, Callable[..., Any]], Any]"
flox/core.py:1175: error: Argument 1 to "partial" has incompatible type "object"; expected "Callable[..., <nothing>]"  [arg-type]
flox/core.py:1228: error: Item "None" of "Optional[Any]" has no attribute "values"  [union-attr]
flox/core.py:1290: error: No overload variant of "zip" matches argument types "Tuple[Any, ...]", "bool"  [call-overload]
flox/core.py:1290: note: Possible overload variants:
flox/core.py:1290: note:     def [_T_co, _T1] zip(cls, Iterable[_T1]) -> zip[Tuple[_T1]]
flox/core.py:1290: note:     def [_T_co, _T1, _T2] zip(cls, Iterable[_T1], Iterable[_T2]) -> zip[Tuple[_T1, _T2]]
flox/core.py:1290: note:     def [_T_co, _T1, _T2, _T3] zip(cls, Iterable[_T1], Iterable[_T2], Iterable[_T3]) -> zip[Tuple[_T1, _T2, _T3]]
flox/core.py:1290: note:     def [_T_co, _T1, _T2, _T3, _T4] zip(cls, Iterable[_T1], Iterable[_T2], Iterable[_T3], Iterable[_T4]) -> zip[Tuple[_T1, _T2, _T3, _T4]]
flox/core.py:1290: note:     def [_T_co, _T1, _T2, _T3, _T4, _T5] zip(cls, Iterable[_T1], Iterable[_T2], Iterable[_T3], Iterable[_T4], Iterable[_T5]) -> zip[Tuple[_T1, _T2, _T3, _T4, _T5]]
flox/core.py:1290: note:     def [_T_co] zip(cls, Iterable[Any], Iterable[Any], Iterable[Any], Iterable[Any], Iterable[Any], Iterable[Any], *iterables: Iterable[Any]) -> zip[Tuple[Any, ...]]
flox/core.py:1457: error: Argument 1 to "_validate_reindex" has incompatible type "Optional[bool]"; expected "bool"  [arg-type]
flox/core.py:1465: error: Incompatible types in assignment (expression has type "Tuple[bool, ...]", variable has type "bool")  [assignment]
flox/core.py:1478: error: Argument 1 to "_convert_expected_groups_to_index" has incompatible type "Union[Tuple[None, ...], Sequence[Any], ndarray[Any, Any]]"; expected "Tuple[Any, ...]"  [arg-type]
flox/core.py:1490: error: Value of type "Optional[Any]" is not indexable  [index]
flox/core.py:1543: error: Argument 4 to "_initialize_aggregation" has incompatible type "Optional[int]"; expected "int"  [arg-type]
flox/core.py:1567: error: Item "ndarray[Any, Any]" of "Union[ndarray[Any, Any], Any]" has no attribute "chunks"  [union-attr]
flox/core.py:1580: error: Item "ndarray[Any, Any]" of "Union[ndarray[Any, Any], Any]" has no attribute "chunks"  [union-attr]
flox/core.py:1608: error: Incompatible types in assignment (expression has type "List[Union[ndarray[Any, Any], Any]]", variable has type "Tuple[Any]")  [assignment]
flox/xarray.py:19: error: Module "xarray" has no attribute "Resample"  [attr-defined]
flox/xarray.py:231: error: Unsupported right operand type for in ("Optional[Hashable]")  [operator]
flox/xarray.py:237: error: "Hashable" has no attribute "__iter__" (not iterable)  [attr-defined]
flox/xarray.py:240: error: "Hashable" has no attribute "__iter__" (not iterable)  [attr-defined]
flox/xarray.py:248: error: Incompatible types in assignment (expression has type "Union[str, Aggregation]", variable has type "str")  [assignment]
flox/xarray.py:256: error: Argument 1 to "len" has incompatible type "Hashable"; expected "Sized"  [arg-type]
flox/xarray.py:277: error: Argument 1 to "_convert_expected_groups_to_index" has incompatible type "List[Any]"; expected "Tuple[Any, ...]"  [arg-type]
flox/xarray.py:277: error: Argument 2 to "_convert_expected_groups_to_index" has incompatible type "Sequence[bool]"; expected "bool"  [arg-type]
flox/xarray.py:278: error: Incompatible types in assignment (expression has type "Tuple[int, ...]", variable has type "List[None]")  [assignment]
flox/xarray.py:278: error: Item "None" of "Optional[Any]" has no attribute "__iter__" (not iterable)  [union-attr]
flox/xarray.py:301: error: "Hashable" has no attribute "__iter__" (not iterable)  [attr-defined]
flox/xarray.py:314: error: Argument 1 to "set" has incompatible type "Hashable"; expected "Iterable[Any]"  [arg-type]
flox/xarray.py:330: error: Argument 1 to "tuple" has incompatible type "Optional[Any]"; expected "Iterable[Any]"  [arg-type]
flox/xarray.py:339: error: "Hashable" has no attribute "__iter__" (not iterable)  [attr-defined]
flox/xarray.py:342: error: Argument 2 to "zip" has incompatible type "Optional[Any]"; expected "Iterable[Any]"  [arg-type]
flox/visualize.py:4: error: Skipping analyzing "matplotlib": module is installed, but missing library stubs or py.typed marker  [import]
flox/visualize.py:5: error: Skipping analyzing "matplotlib.pyplot": module is installed, but missing library stubs or py.typed marker  [import]

@Illviljan
Copy link
Contributor Author

Hmm, those doesn't seem to propagate when I run it on xarray:

!mypy C:\Users\J.W\Documents\GitHub\xarray\xarray --ignore-missing-imports
Documents\GitHub\xarray\xarray\core\concat.py:447: error: Incompatible types in assignment (expression has type "None", variable has type "Variable")
Documents\GitHub\xarray\xarray\tests\test_variable.py:9: error: Library stubs not installed for "pytz" (or incompatible with Python 3.9)
Documents\GitHub\xarray\xarray\tests\test_variable.py:9: note: Hint: "python3 -m pip install types-pytz"
Documents\GitHub\xarray\xarray\tests\test_variable.py:9: note: (or run "mypy --install-types" to install all missing stub packages)
Documents\GitHub\xarray\xarray\tests\test_variable.py:9: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 2 errors in 2 files (checked 137 source files)

What could this mean?

@dcherian
Copy link
Collaborator

dcherian commented May 9, 2022

What could this mean?

No idea. Maybe it's only looking at the external interface (xarray.xarray_reduce?)

@dcherian dcherian merged commit af70b2a into xarray-contrib:main May 9, 2022
@dcherian dcherian mentioned this pull request May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants