-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[ty] Support async
/await
, async with
and yield from
#19595
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
Merged
Merged
Conversation
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
sharkdp
commented
Jul 28, 2025
crates/ty_python_semantic/resources/mdtest/function/return_type.md
Outdated
Show resolved
Hide resolved
Diagnostic diff on typing conformance testsChanges were detected when running ty on typing conformance tests--- old-output.txt 2025-07-30 08:56:13.250732152 +0000
+++ new-output.txt 2025-07-30 08:56:13.314732684 +0000
@@ -87,7 +87,6 @@
aliases_variance.py:18:24: error[non-subscriptable] Cannot subscript object of type `<class 'ClassA[T_co]'>` with no `__class_getitem__` method
aliases_variance.py:28:16: error[non-subscriptable] Cannot subscript object of type `<class 'ClassA[T_co]'>` with no `__class_getitem__` method
aliases_variance.py:44:16: error[non-subscriptable] Cannot subscript object of type `<class 'ClassB[T_co, T_contra]'>` with no `__class_getitem__` method
-annotations_coroutines.py:27:5: error[type-assertion-failure] Argument does not have asserted type `str`
annotations_forward_refs.py:22:7: error[unresolved-reference] Name `ClassA` used when not defined
annotations_forward_refs.py:23:12: error[unresolved-reference] Name `ClassA` used when not defined
annotations_forward_refs.py:49:10: error[invalid-type-form] Variable of type `Literal[1]` is not allowed in a type expression
@@ -102,8 +101,6 @@
annotations_forward_refs.py:96:1: error[type-assertion-failure] Argument does not have asserted type `int`
annotations_generators.py:86:21: error[invalid-return-type] Return type does not match returned value: expected `int`, found `types.GeneratorType`
annotations_generators.py:91:27: error[invalid-return-type] Return type does not match returned value: expected `int`, found `types.AsyncGeneratorType`
-annotations_generators.py:167:5: error[type-assertion-failure] Argument does not have asserted type `AsyncGenerator[str, None]`
-annotations_generators.py:174:5: error[type-assertion-failure] Argument does not have asserted type `AsyncGenerator[str, None]`
annotations_generators.py:193:1: error[type-assertion-failure] Argument does not have asserted type `() -> AsyncIterator[int]`
annotations_methods.py:31:1: error[type-assertion-failure] Argument does not have asserted type `A`
annotations_methods.py:36:1: error[type-assertion-failure] Argument does not have asserted type `B`
@@ -892,4 +889,4 @@
tuples_type_form.py:36:1: error[invalid-assignment] Object of type `tuple[Literal[1], Literal[2], Literal[3], Literal[""]]` is not assignable to `tuple[int, ...]`
typeddicts_operations.py:60:1: error[type-assertion-failure] Argument does not have asserted type `str | None`
typeddicts_type_consistency.py:101:1: error[invalid-assignment] Object of type `Unknown | None` is not assignable to `str`
-Found 893 diagnostics
+Found 890 diagnostics |
|
|
Lint rule | Added | Removed | Changed |
---|---|---|---|
unresolved-attribute |
97 | 0 | 3 |
invalid-argument-type |
10 | 1 | 7 |
invalid-return-type |
11 | 1 | 1 |
unused-ignore-comment |
0 | 8 | 0 |
possibly-unbound-attribute |
6 | 0 | 0 |
call-non-callable |
1 | 0 | 0 |
not-iterable |
1 | 0 | 0 |
unsupported-operator |
1 | 0 | 0 |
Total | 127 | 10 | 11 |
AlexWaygood
reviewed
Jul 28, 2025
7e83283
to
6dda1bf
Compare
6dda1bf
to
dc63efa
Compare
fcd5e5c
to
22619eb
Compare
async
/await
and yield from
async
/await
and yield from
async
/await
, async with
and yield from
22619eb
to
a66477b
Compare
a66477b
to
7ead318
Compare
AlexWaygood
reviewed
Jul 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
AlexWaygood
reviewed
Jul 29, 2025
AlexWaygood
reviewed
Jul 29, 2025
crates/ty_python_semantic/resources/mdtest/expression/yield_and_yield_from.md
Outdated
Show resolved
Hide resolved
AlexWaygood
approved these changes
Jul 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
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
async
functionsawait
expressionsasync with
/ async context managersyield from
expressionsThis PR is generally lacking proper error handling in some cases (e.g. illegal
__await__
attributes). I'm planning to work on this in a follow-up.part of astral-sh/ty#151
closes astral-sh/ty#736
Ecosystem
There are a lot of true positives on
prefect
which look similar to:prefect (https://github.com/PrefectHQ/prefect) + src/integrations/prefect-aws/tests/workers/test_ecs_worker.py:406:12: error[unresolved-attribute] Type `str` has no attribute `status_code`
This is due to a wrong return type annotation here.
mitmproxy (https://github.com/mitmproxy/mitmproxy) + test/mitmproxy/addons/test_clientplayback.py:18:1: error[invalid-argument-type] Argument to function `asynccontextmanager` is incorrect: Expected `(...) -> AsyncIterator[Unknown]`, found `def tcp_server(handle_conn, **server_args) -> Unknown | tuple[str, int]`
This is a true positive. That function should return
AsyncIterator[Address]
, notAddress
.I looked through almost all of the other new diagnostics and they all look like known problems or true positives.
Typing conformance
The typing conformance diff looks good.
Test Plan
New Markdown tests