disabled overlap checks in assert
Fixes #17896
Changes
-
COMPARISON_OVERLAPerrors are being filtered on the assert statement - Regarding the reachability issue, I have also implemented
suppress_unreachable_warnings()after assert statements.
I'm not sure if this is the best approach, particularly on suppress_unreachable_warnings(). Any feedback on this would be great.
Diff from mypy_primer, showing the effect of this PR on open source code:
optuna (https://github.com/optuna/optuna)
+ tests/trial_tests/test_frozen.py:109: error: Unused "type: ignore" comment [unused-ignore]
+ tests/storages_tests/test_heartbeat.py:72: error: Unused "type: ignore" comment [unused-ignore]
+ tests/storages_tests/test_heartbeat.py:229: error: Unused "type: ignore" comment [unused-ignore]
psycopg (https://github.com/psycopg/psycopg)
+ tests/test_pipeline_async.py:57: error: Unused "type: ignore" comment [unused-ignore]
+ tests/test_pipeline.py:60: error: Unused "type: ignore" comment [unused-ignore]
urllib3 (https://github.com/urllib3/urllib3)
+ test/test_collections.py:380: error: Unused "type: ignore" comment [unused-ignore]
+ test/test_collections.py:381: error: Unused "type: ignore" comment [unused-ignore]
- test/test_response.py:179: error: Non-overlapping equality check (left operand type: "Literal[b'', ''] | None", right operand type: "Literal[b'foo']") [comparison-overlap]
artigraph (https://github.com/artigraph/artigraph)
+ tests/arti/test_fingerprints.py:23: error: Unused "type: ignore" comment [unused-ignore]
streamlit (https://github.com/streamlit/streamlit)
- lib/tests/streamlit/testing/element_tree_test.py: note: In function "test_toggle":
- lib/tests/streamlit/testing/element_tree_test.py:920:5: error: Statement is unreachable [unreachable]
- lib/tests/streamlit/runtime/app_session_test.py: note: In member "test_create_scriptrunner" of class "AppSessionTest":
- lib/tests/streamlit/runtime/app_session_test.py:324:9: error: Statement is unreachable [unreachable]
- lib/tests/streamlit/runtime/fragment_test.py: note: In member "test_get" of class "MemoryFragmentStorageTest":
- lib/tests/streamlit/runtime/fragment_test.py:60:16: error: Non-overlapping equality check (left operand type: "Callable[[], Any]", right operand type: "Literal['some_fragment']") [comparison-overlap]
- lib/tests/streamlit/runtime/fragment_test.py:70:16: error: Non-overlapping equality check (left operand type: "Callable[[], Any]", right operand type: "Literal['new_fragment']") [comparison-overlap]
- lib/tests/streamlit/runtime/fragment_test.py:71:16: error: Non-overlapping equality check (left operand type: "Callable[[], Any]", right operand type: "Literal['some_other_fragment']") [comparison-overlap]
- lib/tests/streamlit/runtime/fragment_test.py:95:16: error: Non-overlapping equality check (left operand type: "Callable[[], Any]", right operand type: "Literal['some_fragment']") [comparison-overlap]
- lib/tests/streamlit/runtime/fragment_test.py:215:20: error: Non-overlapping equality check (left operand type: "Callable[..., Never]", right operand type: "Literal[7]") [comparison-overlap]
- lib/tests/streamlit/runtime/state/session_state_test.py: note: In member "test_getitem_serialized" of class "WStateTests":
- lib/tests/streamlit/runtime/state/session_state_test.py:122:16: error: Non-overlapping equality check (left operand type: "Serialized", right operand type: "Value") [comparison-overlap]
- lib/tests/streamlit/elements/slider_test.py: note: In member "test_range_session_state" of class "SliderTest":
- lib/tests/streamlit/elements/slider_test.py:180:16: error: Non-overlapping equality check (left operand type: "int", right operand type: "List[int]") [comparison-overlap]
- lib/tests/streamlit/elements/select_slider_test.py: note: In member "test_range_session_state" of class "SliderTest":
- lib/tests/streamlit/elements/select_slider_test.py:130:16: error: Non-overlapping equality check (left operand type: "str", right operand type: "Tuple[str, str]") [comparison-overlap]
pytest (https://github.com/pytest-dev/pytest)
+ testing/example_scripts/dataclasses/test_compare_two_different_dataclasses.py:21: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_recwarn.py:432: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_pytester.py:40: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_pytester.py:42: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_pytester.py:493: error: Unused "type: ignore[comparison-overlap]" comment [unused-ignore]
+ testing/test_pytester.py:494: error: Unused "type: ignore[comparison-overlap]" comment [unused-ignore]
+ testing/test_monkeypatch.py:63: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_monkeypatch.py:70: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_monkeypatch.py:369: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_monkeypatch.py:418: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_mark.py:40: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_collection.py:64: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_collection.py:66: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_collection.py:67: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_capture.py:889: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_assertrewrite.py:412: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_assertrewrite.py:940: error: Unused "type: ignore" comment [unused-ignore]
+ testing/python/collect.py:810: error: Unused "type: ignore" comment [unused-ignore]
+ testing/python/collect.py:812: error: Unused "type: ignore" comment [unused-ignore]
+ testing/python/collect.py:813: error: Unused "type: ignore" comment [unused-ignore]
werkzeug (https://github.com/pallets/werkzeug)
- tests/test_wrappers.py:1058: error: Non-overlapping identity check (left operand type: "type[list[str]]", right operand type: "type[tuple[Any, ...]]") [comparison-overlap]
- tests/test_wrappers.py:1195: error: Non-overlapping container check (element type: "str", container item type: "tuple[str, str]") [comparison-overlap]
- tests/test_utils.py:78: error: Non-overlapping equality check (left operand type: "Callable[[], Any]", right operand type: "Literal[42]") [comparison-overlap]
- tests/test_utils.py:94: error: Non-overlapping equality check (left operand type: "Callable[[], Any]", right operand type: "Literal[42]") [comparison-overlap]
- tests/test_test.py:701: error: Non-overlapping equality check (left operand type: "list[str]", right operand type: "list[tuple[str, str]]") [comparison-overlap]
- tests/test_test.py:727: error: Non-overlapping equality check (left operand type: "list[str]", right operand type: "list[tuple[str, str]]") [comparison-overlap]
- tests/test_test.py:756: error: Non-overlapping equality check (left operand type: "list[str]", right operand type: "list[tuple[str, str]]") [comparison-overlap]
- tests/test_test.py:761: error: Non-overlapping equality check (left operand type: "Iterable[bytes]", right operand type: "list[str]") [comparison-overlap]
- tests/test_local.py:160: error: Non-overlapping equality check (left operand type: "int", right operand type: "list[int]") [comparison-overlap]
- tests/test_local.py:231: error: Non-overlapping identity check (left operand type: "type[list[Any]]", right operand type: "type[LocalProxy[Any]]") [comparison-overlap]
- tests/test_http.py:84: error: Non-overlapping container check (element type: "str", container item type: "tuple[str, int]") [comparison-overlap]
- tests/test_http.py:85: error: Non-overlapping container check (element type: "str", container item type: "tuple[str, int]") [comparison-overlap]
- tests/test_formparser.py:196: error: Non-overlapping equality check (left operand type: "tuple[IO[bytes], MultiDict[str, str], MultiDict[str, FileStorage]]", right operand type: "tuple[str, MultiDict[Never, Never], MultiDict[Never, Never]]") [comparison-overlap]
- tests/test_formparser.py:438: error: Non-overlapping identity check (left operand type: "TStreamFactory", right operand type: "Callable[[], Any]") [comparison-overlap]
- tests/test_datastructures.py:733: error: Non-overlapping equality check (left operand type: "list[str]", right operand type: "list[tuple[str, str]]") [comparison-overlap]
- tests/test_datastructures.py:817: error: Non-overlapping equality check (left operand type: "list[str]", right operand type: "list[tuple[str, str]]") [comparison-overlap]
- tests/test_datastructures.py:873: error: Non-overlapping equality check (left operand type: "tuple[int, int, int, int]", right operand type: "ImmutableList[int]") [comparison-overlap]
- tests/test_datastructures.py:1020: error: Non-overlapping container check (element type: "str", container item type: "tuple[str, int]") [comparison-overlap]
- tests/test_datastructures.py:1021: error: Non-overlapping container check (element type: "str", container item type: "tuple[str, int]") [comparison-overlap]
- tests/test_datastructures.py:1052: error: Non-overlapping container check (element type: "str", container item type: "tuple[str, int]") [comparison-overlap]
antidote (https://github.com/Finistere/antidote)
+ tests/core/test_type_hints_locals.py:117: error: Unused "type: ignore" comment [unused-ignore]
+ tests/core/test_type_hints_locals.py:124: error: Unused "type: ignore" comment [unused-ignore]
Diff from mypy_primer, showing the effect of this PR on open source code:
optuna (https://github.com/optuna/optuna)
+ tests/trial_tests/test_frozen.py:109: error: Unused "type: ignore" comment [unused-ignore]
+ tests/storages_tests/test_heartbeat.py:72: error: Unused "type: ignore" comment [unused-ignore]
+ tests/storages_tests/test_heartbeat.py:229: error: Unused "type: ignore" comment [unused-ignore]
psycopg (https://github.com/psycopg/psycopg)
+ tests/test_pipeline_async.py:57: error: Unused "type: ignore" comment [unused-ignore]
+ tests/test_pipeline.py:60: error: Unused "type: ignore" comment [unused-ignore]
urllib3 (https://github.com/urllib3/urllib3)
+ test/test_collections.py:380: error: Unused "type: ignore" comment [unused-ignore]
+ test/test_collections.py:381: error: Unused "type: ignore" comment [unused-ignore]
- test/test_response.py:179: error: Non-overlapping equality check (left operand type: "Literal[b'', ''] | None", right operand type: "Literal[b'foo']") [comparison-overlap]
artigraph (https://github.com/artigraph/artigraph)
+ tests/arti/test_fingerprints.py:23: error: Unused "type: ignore" comment [unused-ignore]
streamlit (https://github.com/streamlit/streamlit)
- lib/tests/streamlit/testing/element_tree_test.py: note: In function "test_toggle":
- lib/tests/streamlit/testing/element_tree_test.py:920:5: error: Statement is unreachable [unreachable]
- lib/tests/streamlit/runtime/app_session_test.py: note: In member "test_create_scriptrunner" of class "AppSessionTest":
- lib/tests/streamlit/runtime/app_session_test.py:324:9: error: Statement is unreachable [unreachable]
- lib/tests/streamlit/runtime/fragment_test.py: note: In member "test_get" of class "MemoryFragmentStorageTest":
- lib/tests/streamlit/runtime/fragment_test.py:60:16: error: Non-overlapping equality check (left operand type: "Callable[[], Any]", right operand type: "Literal['some_fragment']") [comparison-overlap]
- lib/tests/streamlit/runtime/fragment_test.py:70:16: error: Non-overlapping equality check (left operand type: "Callable[[], Any]", right operand type: "Literal['new_fragment']") [comparison-overlap]
- lib/tests/streamlit/runtime/fragment_test.py:71:16: error: Non-overlapping equality check (left operand type: "Callable[[], Any]", right operand type: "Literal['some_other_fragment']") [comparison-overlap]
- lib/tests/streamlit/runtime/fragment_test.py:95:16: error: Non-overlapping equality check (left operand type: "Callable[[], Any]", right operand type: "Literal['some_fragment']") [comparison-overlap]
- lib/tests/streamlit/runtime/fragment_test.py:215:20: error: Non-overlapping equality check (left operand type: "Callable[..., Never]", right operand type: "Literal[7]") [comparison-overlap]
- lib/tests/streamlit/runtime/state/session_state_test.py: note: In member "test_getitem_serialized" of class "WStateTests":
- lib/tests/streamlit/runtime/state/session_state_test.py:122:16: error: Non-overlapping equality check (left operand type: "Serialized", right operand type: "Value") [comparison-overlap]
- lib/tests/streamlit/elements/slider_test.py: note: In member "test_range_session_state" of class "SliderTest":
- lib/tests/streamlit/elements/slider_test.py:180:16: error: Non-overlapping equality check (left operand type: "int", right operand type: "List[int]") [comparison-overlap]
- lib/tests/streamlit/elements/select_slider_test.py: note: In member "test_range_session_state" of class "SliderTest":
- lib/tests/streamlit/elements/select_slider_test.py:130:16: error: Non-overlapping equality check (left operand type: "str", right operand type: "Tuple[str, str]") [comparison-overlap]
pytest (https://github.com/pytest-dev/pytest)
+ testing/example_scripts/dataclasses/test_compare_two_different_dataclasses.py:21: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_recwarn.py:432: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_pytester.py:40: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_pytester.py:42: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_pytester.py:493: error: Unused "type: ignore[comparison-overlap]" comment [unused-ignore]
+ testing/test_pytester.py:494: error: Unused "type: ignore[comparison-overlap]" comment [unused-ignore]
+ testing/test_monkeypatch.py:63: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_monkeypatch.py:70: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_monkeypatch.py:369: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_monkeypatch.py:418: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_mark.py:40: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_collection.py:64: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_collection.py:66: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_collection.py:67: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_capture.py:889: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_assertrewrite.py:412: error: Unused "type: ignore" comment [unused-ignore]
+ testing/test_assertrewrite.py:940: error: Unused "type: ignore" comment [unused-ignore]
+ testing/python/collect.py:810: error: Unused "type: ignore" comment [unused-ignore]
+ testing/python/collect.py:812: error: Unused "type: ignore" comment [unused-ignore]
+ testing/python/collect.py:813: error: Unused "type: ignore" comment [unused-ignore]
werkzeug (https://github.com/pallets/werkzeug)
- tests/test_wrappers.py:1058: error: Non-overlapping identity check (left operand type: "type[list[str]]", right operand type: "type[tuple[Any, ...]]") [comparison-overlap]
- tests/test_wrappers.py:1195: error: Non-overlapping container check (element type: "str", container item type: "tuple[str, str]") [comparison-overlap]
- tests/test_utils.py:78: error: Non-overlapping equality check (left operand type: "Callable[[], Any]", right operand type: "Literal[42]") [comparison-overlap]
- tests/test_utils.py:94: error: Non-overlapping equality check (left operand type: "Callable[[], Any]", right operand type: "Literal[42]") [comparison-overlap]
- tests/test_test.py:701: error: Non-overlapping equality check (left operand type: "list[str]", right operand type: "list[tuple[str, str]]") [comparison-overlap]
- tests/test_test.py:727: error: Non-overlapping equality check (left operand type: "list[str]", right operand type: "list[tuple[str, str]]") [comparison-overlap]
- tests/test_test.py:756: error: Non-overlapping equality check (left operand type: "list[str]", right operand type: "list[tuple[str, str]]") [comparison-overlap]
- tests/test_test.py:761: error: Non-overlapping equality check (left operand type: "Iterable[bytes]", right operand type: "list[str]") [comparison-overlap]
- tests/test_local.py:160: error: Non-overlapping equality check (left operand type: "int", right operand type: "list[int]") [comparison-overlap]
- tests/test_local.py:231: error: Non-overlapping identity check (left operand type: "type[list[Any]]", right operand type: "type[LocalProxy[Any]]") [comparison-overlap]
- tests/test_http.py:84: error: Non-overlapping container check (element type: "str", container item type: "tuple[str, int]") [comparison-overlap]
- tests/test_http.py:85: error: Non-overlapping container check (element type: "str", container item type: "tuple[str, int]") [comparison-overlap]
- tests/test_formparser.py:196: error: Non-overlapping equality check (left operand type: "tuple[IO[bytes], MultiDict[str, str], MultiDict[str, FileStorage]]", right operand type: "tuple[str, MultiDict[Never, Never], MultiDict[Never, Never]]") [comparison-overlap]
- tests/test_formparser.py:438: error: Non-overlapping identity check (left operand type: "TStreamFactory", right operand type: "Callable[[], Any]") [comparison-overlap]
- tests/test_datastructures.py:733: error: Non-overlapping equality check (left operand type: "list[str]", right operand type: "list[tuple[str, str]]") [comparison-overlap]
- tests/test_datastructures.py:817: error: Non-overlapping equality check (left operand type: "list[str]", right operand type: "list[tuple[str, str]]") [comparison-overlap]
- tests/test_datastructures.py:873: error: Non-overlapping equality check (left operand type: "tuple[int, int, int, int]", right operand type: "ImmutableList[int]") [comparison-overlap]
- tests/test_datastructures.py:1020: error: Non-overlapping container check (element type: "str", container item type: "tuple[str, int]") [comparison-overlap]
- tests/test_datastructures.py:1021: error: Non-overlapping container check (element type: "str", container item type: "tuple[str, int]") [comparison-overlap]
- tests/test_datastructures.py:1052: error: Non-overlapping container check (element type: "str", container item type: "tuple[str, int]") [comparison-overlap]
antidote (https://github.com/Finistere/antidote)
+ tests/core/test_type_hints_locals.py:117: error: Unused "type: ignore" comment [unused-ignore]
+ tests/core/test_type_hints_locals.py:124: error: Unused "type: ignore" comment [unused-ignore]
Hi @hauntsaninja, thanks for the feedback!
reveal_type not revealing anything does indeed feel buggy. One another possible solutions that I came up with might be disabling should_narrow_by_identity, but that will still lead to incorrect results with reveal_type so I'm not sure if it's good enough.
I'm open to discussing any other possible solution that might address this issue more effectively and I would be happy to try my best to implement it!