KEMBAR78
match Field TypeVar variance in models.fields.related by asottile · Pull Request #2292 · typeddjango/django-stubs · GitHub
Skip to content

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
@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