mirror of
https://github.com/davidhalter/django-stubs.git
synced 2026-02-21 00:58:29 +08:00
Fix Field arguments variance (#573)
* Fix Field arguments variance * fixup! Fix Field arguments variance Test field can be used as bsse type
This commit is contained in:
@@ -150,4 +150,18 @@
|
||||
username = models.CharField(max_length=100)
|
||||
|
||||
class MyModel(AuthMixin, models.Model):
|
||||
pass
|
||||
pass
|
||||
- case: can_narrow_field_type
|
||||
main: |
|
||||
from typing import cast, NewType
|
||||
from django.db import models
|
||||
Year = NewType("Year", int)
|
||||
class Book(models.Model):
|
||||
published = cast(models.Field[Year, Year], models.IntegerField())
|
||||
book = Book()
|
||||
reveal_type(book.published) # N: Revealed type is 'main.Year*'
|
||||
book.published = 2006 # E: Incompatible types in assignment (expression has type "int", variable has type "Year")
|
||||
book.published = Year(2006)
|
||||
reveal_type(book.published) # N: Revealed type is 'main.Year*'
|
||||
def accepts_int(arg: int) -> None: ...
|
||||
accepts_int(book.published)
|
||||
|
||||
Reference in New Issue
Block a user