Skip to content

Fix type context for cast() - #12614

Closed
hauntsaninja wants to merge 1 commit into
python:masterfrom
hauntsaninja:cast
Closed

hauntsaninja wants to merge 1 commit into
python:masterfrom
hauntsaninja:cast

Conversation

@hauntsaninja

Copy link
Copy Markdown
Collaborator

No description provided.

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is right, let's see if mypy-primer agrees.

@hauntsaninja

hauntsaninja commented Apr 18, 2022 •

Copy link
Copy Markdown
Collaborator Author

Unit tests agree, both new and old!

@JelleZijlstra

Copy link
Copy Markdown
Member

(#12612 for context)

@github-actions

Copy link
Copy Markdown
Contributor

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

cwltool (https://github.com/common-workflow-language/cwltool)
+ cwltool/provenance.py: note: In member "add_data_file" of class "ResearchObject":
+ cwltool/provenance.py:828:47: error: Redundant cast to "Aggregate"  [redundant-cast]
+ cwltool/pathmapper.py: note: In member "visit" of class "PathMapper":
+ cwltool/pathmapper.py:116:62: error: Argument 2 to "get" of "Mapping" has incompatible type "List[<nothing>]"; expected "Union[str, float, MutableSequence[Union[None, bool, str, int, float, MutableSequence[Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]], MutableMapping[str, Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]]]], MutableMapping[str, Union[None, bool, str, int, float, MutableSequence[Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]], MutableMapping[str, Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]]]], None, List[MutableMapping[str, Union[bool, str, int, float, MutableSequence[Union[None, bool, str, int, float, MutableSequence[Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]], MutableMapping[str, Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]]]], MutableMapping[str, Union[None, bool, str, int, float, MutableSequence[Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]], MutableMapping[str, Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]]]], None]]]]"  [arg-type]
+ cwltool/pathmapper.py:116:62: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
+ cwltool/pathmapper.py:116:62: note: Consider using "Sequence" instead, which is covariant
+ cwltool/pathmapper.py:158:69: error: Argument 2 to "get" of "Mapping" has incompatible type "List[<nothing>]"; expected "Union[str, float, MutableSequence[Union[None, bool, str, int, float, MutableSequence[Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]], MutableMapping[str, Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]]]], MutableMapping[str, Union[None, bool, str, int, float, MutableSequence[Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]], MutableMapping[str, Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]]]], None, List[MutableMapping[str, Union[bool, str, int, float, MutableSequence[Union[None, bool, str, int, float, MutableSequence[Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]], MutableMapping[str, Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]]]], MutableMapping[str, Union[None, bool, str, int, float, MutableSequence[Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]], MutableMapping[str, Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]]]], None]]]]"  [arg-type]
+ cwltool/pathmapper.py:158:69: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
+ cwltool/pathmapper.py:158:69: note: Consider using "Sequence" instead, which is covariant
+ cwltool/expression.py: note: In function "do_eval":
+ cwltool/expression.py:389:71: error: Argument 2 to "get" of "Mapping" has incompatible type "List[<nothing>]"; expected "Union[str, float, MutableSequence[Union[None, bool, str, int, float, MutableSequence[Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]], MutableMapping[str, Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]]]], MutableMapping[str, Union[None, bool, str, int, float, MutableSequence[Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]], MutableMapping[str, Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]]]], None, List[str]]"  [arg-type]
+ cwltool/expression.py:389:71: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
+ cwltool/expression.py:389:71: note: Consider using "Sequence" instead, which is covariant
+ cwltool/builder.py: note: In member "generate_arg" of class "Builder":
+ cwltool/builder.py:683:24: error: Redundant cast to "List[str]"  [redundant-cast]
+ tests/test_pack.py:134:135: note: (Skipping most remaining errors due to unresolved imports or missing stubs; fix these first)
- tests/test_pack.py:134:2: error: Untyped decorator makes function "test_pack_missing_cwlVersion" untyped  [misc]
- tests/test_pack.py:206:2: error: Untyped decorator makes function "test_packed_workflow_execution" untyped  [misc]
- tests/test_pack.py:207:2: error: Untyped decorator makes function "test_packed_workflow_execution" untyped  [misc]
- tests/test_override.py:77:2: error: Untyped decorator makes function "test_overrides" untyped  [misc]
- tests/test_override.py:78:2: error: Untyped decorator makes function "test_overrides" untyped  [misc]
- tests/test_override.py:124:2: error: Untyped decorator makes function "test_overrides_fails" untyped  [misc]
- tests/test_override.py:125:2: error: Untyped decorator makes function "test_overrides_fails" untyped  [misc]
- tests/test_mpi.py:42:2: error: Untyped decorator makes function "fake_mpi_conf" untyped  [misc]
- tests/test_mpi.py:283:2: error: Untyped decorator makes function "schema_ext11" untyped  [misc]
- tests/test_js_sandbox.py:29:2: error: Untyped decorator makes function "test_node_version" untyped  [misc]
- tests/test_js_sandbox.py:68:2: error: Untyped decorator makes function "test_value_from_two_concatenated_expressions_podman" untyped  [misc]
- tests/test_js_sandbox.py:87:88: note: (Skipping most remaining errors due to unresolved imports or missing stubs; fix these first)

kopf (https://github.com/nolar/kopf)
+ kopf/_core/engines/posting.py:98: error: Argument 1 to "walk" has incompatible type "Union[Body, Iterable[Body]]"; expected "Iterable[Iterable[<nothing>]]"
+ kopf/_core/engines/posting.py:111: error: Argument 1 to "walk" has incompatible type "Union[Body, Iterable[Body]]"; expected "Iterable[Iterable[<nothing>]]"
+ kopf/_core/engines/posting.py:124: error: Argument 1 to "walk" has incompatible type "Union[Body, Iterable[Body]]"; expected "Iterable[Iterable[<nothing>]]"
+ kopf/_core/engines/posting.py:142: error: Argument 1 to "walk" has incompatible type "Union[Body, Iterable[Body]]"; expected "Iterable[Iterable[<nothing>]]"

core (https://github.com/home-assistant/core)
+ homeassistant/loader.py:266: error: Redundant cast to "DHCPMatcher"  [redundant-cast]
+ homeassistant/loader.py:266: error: Expected TypedDict key to be string literal  [misc]
+ homeassistant/components/nanoleaf/config_flow.py:133: error: Redundant cast to "Dict[Any, Any]"  [redundant-cast]
+ homeassistant/components/nanoleaf/config_flow.py:136: error: Argument 1 to "async_add_executor_job" of "HomeAssistant" has incompatible type "Callable[[str, Union[List[Any], Dict[Any, Any], None]], Union[List[Any], Dict[Any, Any]]]"; expected "Callable[..., Dict[Any, Any]]"  [arg-type]
+ homeassistant/components/group/light.py:301: error: Redundant cast to "Set[str]"  [redundant-cast]

@hauntsaninja

Copy link
Copy Markdown
Collaborator Author

:-( There's at least some issue involving typeddicts that's genuine. Not immediately obvious to me how to fix. I don't think this is particularly important and it's very annoying for mypy to get things wrong here (since cast is a "please shut up")

@hauntsaninja
hauntsaninja deleted the cast branch April 18, 2022 05:02
@JelleZijlstra

Copy link
Copy Markdown
Member

Which one was that? In kopf it looked like it found a real issue that was previously hidden by the Any type context.

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