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

Improve narrowing return types #6

Merged
merged 5 commits into from
May 28, 2024
Merged

Improve narrowing return types #6

merged 5 commits into from
May 28, 2024

Conversation

delfick
Copy link
Owner

@delfick delfick commented May 28, 2024

Prior to this we would only resolve concrete annotations that used type variables on functions. This change makes it so that logic works for all annotations rather than only DefaultQuerySet, and also on methods.

It also adds logic to give a useful warning when a type guard is used with a concrete annotation that depends on a typevar. In that situation the mypy plugin system doesn't not provide an opportunity to resolve such an annotation where it can also modify the type guard.

@delfick delfick force-pushed the better-return-types branch 2 times, most recently from 4a02ae2 to 8c5b486 Compare May 28, 2024 04:27
delfick added 5 commits May 28, 2024 14:41
Turns out that mypy plugin system doesn't give us an opportunity to
change the typeguard when it relies on a Type Var.

This is because we only know the value of the type var where it's
called, which is the get_method/function_hook but those can only change
the return type and don't have the ability to change the type guard
@delfick delfick force-pushed the better-return-types branch from 8c5b486 to ebe6cdf Compare May 28, 2024 04:45
@delfick delfick merged commit 3385fd0 into main May 28, 2024
15 checks passed
@delfick delfick deleted the better-return-types branch May 28, 2024 04:57
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.

1 participant