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

match Field TypeVar variance in models.fields.related #2292

Merged
merged 1 commit into from
Jul 30, 2024

Conversation

asottile
Copy link
Contributor

previously failing with:

_____________________________ foreign_key_subclass _____________________________
/home/asottile/workspace/django-stubs/tests/typecheck/fields/test_related.yml:90: 
E   pytest_mypy_plugins.utils.TypecheckAssertionError: Invalid output: 
E   Actual:
E     myapp/models:7: error: Variance of TypeVar "_ST" incompatible with variance in parent type  [type-var] (diff)
E     myapp/models:7: error: Variance of TypeVar "_GT" incompatible with variance in parent type  [type-var] (diff)
E   Expected:
E     (empty)

I'm not sure how this wasn't a problem before 5.0.4 for us but it certainly is now!

I'm also surprised mypy doesn't report this same error for related.pyi itself -- there must be some special-cased rules that .pyi files don't have to follow

@asottile
Copy link
Contributor Author

failure looks like a github flake

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Source:

# __set__ value type
_ST = TypeVar("_ST", contravariant=True)
# __get__ return type
_GT = TypeVar("_GT", covariant=True)
class Field(RegisterLookupMixin, Generic[_ST, _GT]):

@sobolevn sobolevn merged commit 9b50861 into typeddjango:master Jul 30, 2024
36 checks passed
@asottile asottile deleted the foreign-key-variance branch August 4, 2024 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants