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

#1872 issue: Update narrowing_typeguar.py Update narrowing_typeis.py #1928

Closed

Conversation

RSzipper
Copy link

This PR addresses the issue where TypeIs and TypeGuard do not support async functions, preventing proper type narrowing in asynchronous contexts.

Changes Made:
✅ Added support for async TypeGuard (TypeIs) by modifying type checking behavior.
✅ Updated test cases to cover async scenarios and ensure expected narrowing.
✅ Refactored narrowing/typeis.py and narrowing/typeguard.py to handle async evaluation correctly.
✅ Ensured backward compatibility with existing TypeGuard behavior.

Issue Fixed:
🔗 Closes #1872 (Async TypeIs not narrowing properly)

Impact & Testing:
✔️ All existing tests pass.
✔️ New tests validate async narrowing correctness.
✔️ Maintains compatibility with synchronous TypeGuard usage.

@ghost
Copy link

ghost commented Feb 19, 2025

All commit authors signed the Contributor License Agreement.
CLA signed

@erictraut
Copy link
Collaborator

The conformance tests are designed to validate functionality mandated by the typing spec. You'll see that most sections of the tests are preceded by quoted sections of the spec.

The test you've added here is not based on anything in the spec, so I don't think it's appropriate to add to the conformance test.

I'm the author of the original PEP 647 that introduced TypedGuard, and the use case that you're describing here is definitely not mandated by — or even contemplated by — the original PEP. Nor is it supported by any existing type checkers.

If you'd like to pursue an update to the spec, the process can be found here.

Closing the PR.

@erictraut erictraut closed this Feb 19, 2025
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.

Awaitable typeguards
2 participants