[ty] Add diagnostics to validate TypeIs and TypeGuard definitions#22300
Merged
charliermarsh merged 1 commit intomainfrom Jan 14, 2026
Merged
[ty] Add diagnostics to validate TypeIs and TypeGuard definitions#22300charliermarsh merged 1 commit intomainfrom
TypeIs and TypeGuard definitions#22300charliermarsh merged 1 commit intomainfrom
Conversation
Diagnostic diff on typing conformance testsChanges were detected when running ty on typing conformance tests--- old-output.txt 2026-01-13 23:29:49.973606373 +0000
+++ new-output.txt 2026-01-13 23:29:50.352609209 +0000
@@ -762,16 +762,22 @@
namedtuples_usage.py:43:5: error[not-subscriptable] Cannot delete subscript on object of type `Point` with no `__delitem__` method
namedtuples_usage.py:52:1: error[invalid-assignment] Too many values to unpack: Expected 2
namedtuples_usage.py:53:1: error[invalid-assignment] Not enough values to unpack: Expected 4
+narrowing_typeguard.py:102:23: error[invalid-type-guard-definition] `TypeGuard` function must have a parameter to narrow
+narrowing_typeguard.py:107:22: error[invalid-type-guard-definition] `TypeGuard` function must have a parameter to narrow
narrowing_typeguard.py:128:20: error[invalid-argument-type] Argument to function `takes_callable_str` is incorrect: Expected `(object, /) -> str`, found `def simple_typeguard(val: object) -> TypeGuard[int]`
narrowing_typeguard.py:148:26: error[invalid-argument-type] Argument to function `takes_callable_str_proto` is incorrect: Expected `CallableStrProto`, found `def simple_typeguard(val: object) -> TypeGuard[int]`
narrowing_typeis.py:21:9: error[type-assertion-failure] Type `tuple[str, ...]` does not match asserted type `tuple[str, ...] & ~tuple[str, str]`
narrowing_typeis.py:35:18: error[invalid-assignment] Object of type `object` is not assignable to `int`
narrowing_typeis.py:38:9: error[type-assertion-failure] Type `int` does not match asserted type `int & ~Awaitable[object]`
+narrowing_typeis.py:105:23: error[invalid-type-guard-definition] `TypeIs` function must have a parameter to narrow
+narrowing_typeis.py:110:22: error[invalid-type-guard-definition] `TypeIs` function must have a parameter to narrow
narrowing_typeis.py:132:20: error[invalid-argument-type] Argument to function `takes_callable_str` is incorrect: Expected `(object, /) -> str`, found `def simple_typeguard(val: object) -> TypeIs[int]`
narrowing_typeis.py:152:26: error[invalid-argument-type] Argument to function `takes_callable_str_proto` is incorrect: Expected `CallableStrProto`, found `def simple_typeguard(val: object) -> TypeIs[int]`
narrowing_typeis.py:169:17: error[invalid-argument-type] Argument to function `takes_typeguard` is incorrect: Expected `(object, /) -> TypeGuard[int]`, found `def is_int_typeis(val: object) -> TypeIs[int]`
narrowing_typeis.py:170:14: error[invalid-argument-type] Argument to function `takes_typeis` is incorrect: Expected `(object, /) -> TypeIs[int]`, found `def is_int_typeguard(val: object) -> TypeGuard[int]`
narrowing_typeis.py:191:18: error[invalid-argument-type] Argument to function `takes_int_typeis` is incorrect: Expected `(object, /) -> TypeIs[int]`, found `def bool_typeis(val: object) -> TypeIs[bool]`
+narrowing_typeis.py:195:27: error[invalid-type-guard-definition] Narrowed type `str` is not assignable to the declared parameter type `int`
+narrowing_typeis.py:199:45: error[invalid-type-guard-definition] Narrowed type `list[int]` is not assignable to the declared parameter type `list[object]`
overloads_basic.py:39:1: error[invalid-argument-type] Method `__getitem__` of type `Overload[(__i: int, /) -> int, (__s: slice[Any, Any, Any], /) -> bytes]` cannot be called with key of type `Literal[""]` on object of type `Bytes`
overloads_definitions.py:20:5: error[invalid-overload] Overloaded function `func1` requires at least two overloads
overloads_definitions.py:33:5: error[invalid-overload] Overloads for function `func2` must be followed by a non-`@overload`-decorated implementation function
@@ -1029,4 +1035,4 @@
typeddicts_usage.py:28:17: error[missing-typed-dict-key] Missing required key 'name' in TypedDict `Movie` constructor
typeddicts_usage.py:28:18: error[invalid-key] Unknown key "title" for TypedDict `Movie`: Unknown key "title"
typeddicts_usage.py:40:24: error[invalid-type-form] The special form `typing.TypedDict` is not allowed in type expressions
-Found 1031 diagnostics
+Found 1037 diagnostics
|
|
48ae59b to
d9f25ef
Compare
TypeIs and TypeGuard definitions
5ca7e86 to
436238c
Compare
AlexWaygood
reviewed
Jan 13, 2026
Member
There was a problem hiding this comment.
hmm, can we either add some snapshots here or assert the error message in some of these # error: comments? Currently it's a bit hard to see why we're complaining about each line, and what the message presented to the user would be
Member
|
The ecosystem diagnostics on mypy are weird, but I'm guessing it's the usual confusion of us not understanding the |
436238c to
334fd4d
Compare
334fd4d to
9d65c4e
Compare
9d65c4e to
51c108f
Compare
AlexWaygood
pushed a commit
that referenced
this pull request
Jan 14, 2026
…#22300) ## Summary Closes astral-sh/ty#2267.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes astral-sh/ty#2267.