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

Represent finite types as union of literals for checking overloads #17437

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

sterliakov
Copy link
Contributor

May close #14764. Not even close to completion, I just want to see mypy-primer output now

This comment has been minimized.

Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/tools/numeric.py:215: error: Unused "type: ignore" comment  [unused-ignore]
+ pandas/io/parsers/base_parser.py:640: error: Unused "type: ignore" comment  [unused-ignore]
+ pandas/io/parsers/base_parser.py:657: error: Argument 1 to "IntegerArray" has incompatible type "ExtensionArray | ndarray[Any, Any]"; expected "ndarray[Any, Any]"  [arg-type]
+ pandas/io/parsers/base_parser.py:659: error: Argument 1 to "BooleanArray" has incompatible type "ExtensionArray | ndarray[Any, Any]"; expected "ndarray[Any, Any]"  [arg-type]
+ pandas/io/parsers/base_parser.py:661: error: Argument 1 to "FloatingArray" has incompatible type "ExtensionArray | ndarray[Any, Any]"; expected "ndarray[Any, Any]"  [arg-type]
+ pandas/io/parsers/base_parser.py:676: error: Unused "type: ignore" comment  [unused-ignore]
+ pandas/io/parsers/base_parser.py:681: error: Argument 1 to "BooleanArray" has incompatible type "ExtensionArray | ndarray[Any, Any]"; expected "ndarray[Any, Any]"  [arg-type]
+ pandas/io/parsers/base_parser.py:684: error: Argument 1 to "is_datetime_array" has incompatible type "ExtensionArray | ndarray[Any, Any]"; expected "ndarray[Any, Any]"  [arg-type]

mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
+ pymongo/asynchronous/database.py:906: error: Not all union combinations were tried because there are too many unions  [misc]

streamlit (https://github.com/streamlit/streamlit)
- lib/tests/streamlit/elements/file_uploader_test.py:106:26: error: No overload variant matches argument types "str", "str", "bool"  [call-overload]
- lib/tests/streamlit/elements/file_uploader_test.py:106:26: note: Possible overload variants:
- lib/tests/streamlit/elements/file_uploader_test.py:106:26: note:     def file_uploader(self, label: str, type: Union[str, Sequence[str], None], accept_multiple_files: Literal[True], key: Optional[Union[str, int]] = ..., help: Optional[str] = ..., on_change: Optional[Callable[..., None]] = ..., args: Optional[Tuple[Any, ...]] = ..., kwargs: Optional[Dict[str, Any]] = ..., *, disabled: bool = ..., label_visibility: Literal['visible', 'hidden', 'collapsed'] = ...) -> Optional[List[UploadedFile]]
- lib/tests/streamlit/elements/file_uploader_test.py:106:26: note:     def file_uploader(self, label: str, type: Union[str, Sequence[str], None], accept_multiple_files: Literal[False] = ..., key: Optional[Union[str, int]] = ..., help: Optional[str] = ..., on_change: Optional[Callable[..., None]] = ..., args: Optional[Tuple[Any, ...]] = ..., kwargs: Optional[Dict[str, Any]] = ..., *, disabled: bool = ..., label_visibility: Literal['visible', 'hidden', 'collapsed'] = ...) -> Optional[UploadedFile]
- lib/tests/streamlit/elements/file_uploader_test.py:106:26: note:     def file_uploader(self, label: str, *, accept_multiple_files: Literal[True], type: Union[str, Sequence[str], None] = ..., key: Optional[Union[str, int]] = ..., help: Optional[str] = ..., on_change: Optional[Callable[..., None]] = ..., args: Optional[Tuple[Any, ...]] = ..., kwargs: Optional[Dict[str, Any]] = ..., disabled: bool = ..., label_visibility: Literal['visible', 'hidden', 'collapsed'] = ...) -> Optional[List[UploadedFile]]
- lib/tests/streamlit/elements/file_uploader_test.py:106:26: note:     def file_uploader(self, label: str, *, accept_multiple_files: Literal[False] = ..., type: Union[str, Sequence[str], None] = ..., key: Optional[Union[str, int]] = ..., help: Optional[str] = ..., on_change: Optional[Callable[..., None]] = ..., args: Optional[Tuple[Any, ...]] = ..., kwargs: Optional[Dict[str, Any]] = ..., disabled: bool = ..., label_visibility: Literal['visible', 'hidden', 'collapsed'] = ...) -> Optional[UploadedFile]
+ lib/tests/streamlit/elements/file_uploader_test.py:118:45: error: Argument 1 to "zip" has incompatible type "Union[List[UploadedFile], UploadedFile, None]"; expected "Iterable[Iterable[object]]"  [arg-type]
+ lib/tests/streamlit/elements/file_uploader_test.py:119:38: error: "Iterable[object]" has no attribute "name"  [attr-defined]
+ lib/tests/streamlit/elements/file_uploader_test.py:120:38: error: "Iterable[object]" has no attribute "type"  [attr-defined]
+ lib/tests/streamlit/elements/file_uploader_test.py:121:38: error: "Iterable[object]" has no attribute "size"  [attr-defined]
+ lib/tests/streamlit/elements/file_uploader_test.py:122:38: error: "Iterable[object]" has no attribute "getvalue"  [attr-defined]
+ lib/tests/streamlit/elements/file_uploader_test.py:126:34: error: Item "List[UploadedFile]" of "Union[List[UploadedFile], UploadedFile, None]" has no attribute "name"  [union-attr]
+ lib/tests/streamlit/elements/file_uploader_test.py:126:34: error: Item "None" of "Union[List[UploadedFile], UploadedFile, None]" has no attribute "name"  [union-attr]
+ lib/tests/streamlit/elements/file_uploader_test.py:127:34: error: Item "List[UploadedFile]" of "Union[List[UploadedFile], UploadedFile, None]" has no attribute "type"  [union-attr]
+ lib/tests/streamlit/elements/file_uploader_test.py:127:34: error: Item "None" of "Union[List[UploadedFile], UploadedFile, None]" has no attribute "type"  [union-attr]
+ lib/tests/streamlit/elements/file_uploader_test.py:128:34: error: Item "List[UploadedFile]" of "Union[List[UploadedFile], UploadedFile, None]" has no attribute "size"  [union-attr]
+ lib/tests/streamlit/elements/file_uploader_test.py:128:34: error: Item "None" of "Union[List[UploadedFile], UploadedFile, None]" has no attribute "size"  [union-attr]
+ lib/tests/streamlit/elements/file_uploader_test.py:129:34: error: Item "List[UploadedFile]" of "Union[List[UploadedFile], UploadedFile, None]" has no attribute "getvalue"  [union-attr]
+ lib/tests/streamlit/elements/file_uploader_test.py:129:34: error: Item "None" of "Union[List[UploadedFile], UploadedFile, None]" has no attribute "getvalue"  [union-attr]

pydantic (https://github.com/pydantic/pydantic)
+ pydantic/v1/dataclasses.py:214: error: Not all union combinations were tried because there are too many unions  [misc]
+ pydantic/dataclasses.py:233: error: Not all union combinations were tried because there are too many unions  [misc]
+ pydantic/dataclasses.py:233: note: Error code "misc" not covered by "type: ignore" comment

hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
+ src/hydra_zen/structured_configs/_implementations.py:1175: error: Not all union combinations were tried because there are too many unions  [misc]
+ src/hydra_zen/structured_configs/_implementations.py:3684: error: Incompatible return value type (got "Any | Builds[type[_T]]", expected "ZenPartialBuilds[type[_T]] | HydraPartialBuilds[type[_T]]")  [return-value]

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.

(🐞) overloads that exhaust finite Literals(bool/Enum) not treated as exhaustive
1 participant