|
46 | 46 |
|
47 | 47 | _T = TypeVar('_T', bound=models.Model) |
48 | 48 | class Base(Generic[_T]): |
49 | | - def __init__(self, model_cls: Type[_T]): |
| 49 | + def __init__(self, model_cls: Type[_T]) -> None: |
50 | 50 | self.model_cls = model_cls |
51 | 51 | reveal_type(self.model_cls._default_manager) # N: Revealed type is "django.db.models.manager.BaseManager[_T`1]" |
52 | 52 | class MyModel(models.Model): |
|
71 | 71 |
|
72 | 72 | _T = TypeVar('_T', bound=models.Model) |
73 | 73 | class Base(Generic[_T]): |
74 | | - def __init__(self, model_cls: Type[_T]): |
| 74 | + def __init__(self, model_cls: Type[_T]) -> None: |
75 | 75 | self.model_cls = model_cls |
76 | 76 | reveal_type(self.model_cls._base_manager) # N: Revealed type is "django.db.models.manager.BaseManager[_T`1]" |
77 | 77 | class MyModel(models.Model): |
|
350 | 350 | - path: myapp/__init__.py |
351 | 351 | - path: myapp/models.py |
352 | 352 | content: | |
| 353 | + from typing import Any |
353 | 354 | from django.db import models |
354 | 355 | class MyManager(models.Manager): |
355 | 356 | def get_instance(self) -> int: |
356 | 357 | pass |
357 | | - def get_instance_untyped(self, name): |
| 358 | + def get_instance_untyped(self, name: str): |
358 | 359 | pass |
359 | 360 | class User(models.Model): |
360 | 361 | objects = MyManager() |
|
389 | 390 | installed_apps: |
390 | 391 | - myapp |
391 | 392 | out: | |
392 | | - myapp/models:4: error: Return type "MyModel" of "create" incompatible with return type "_T" in supertype "BaseManager" |
393 | | - myapp/models:5: error: Incompatible return value type (got "_T", expected "MyModel") |
| 393 | + myapp/models:5: error: Return type "MyModel" of "create" incompatible with return type "_T" in supertype "BaseManager" |
| 394 | + myapp/models:6: error: Incompatible return value type (got "_T", expected "MyModel") |
394 | 395 | files: |
395 | 396 | - path: myapp/__init__.py |
396 | 397 | - path: myapp/models.py |
397 | 398 | content: | |
| 399 | + from typing import Any |
398 | 400 | from django.db import models |
399 | 401 | class MyModelManager(models.Manager): |
400 | 402 |
|
401 | | - def create(self, **kwargs) -> 'MyModel': |
402 | | - return super().create(**kwargs) |
| 403 | + def create(self, **kwargs: Any) -> 'MyModel': |
| 404 | + return super().create(**kwargs) |
403 | 405 |
|
404 | 406 |
|
405 | 407 | class MyModel(models.Model): |
406 | | - objects = MyModelManager() |
| 408 | + objects = MyModelManager() |
407 | 409 |
|
408 | 410 |
|
409 | 411 | - case: override_manager_create2 |
|
416 | 418 | - path: myapp/__init__.py |
417 | 419 | - path: myapp/models.py |
418 | 420 | content: | |
| 421 | + from typing import Any |
419 | 422 | from django.db import models |
420 | 423 | class MyModelManager(models.Manager['MyModel']): |
421 | 424 |
|
422 | | - def create(self, **kwargs) -> 'MyModel': |
423 | | - return super().create(**kwargs) |
| 425 | + def create(self, **kwargs: Any) -> 'MyModel': |
| 426 | + return super().create(**kwargs) |
424 | 427 |
|
425 | 428 | class MyModel(models.Model): |
426 | | -
|
427 | | - objects = MyModelManager() |
| 429 | + objects = MyModelManager() |
428 | 430 |
|
429 | 431 | - case: regression_manager_scope_foreign |
430 | 432 | main: | |
|
488 | 490 | class InvisibleUnresolvable(AbstractUnresolvable): |
489 | 491 | text = models.TextField() |
490 | 492 |
|
491 | | - def process_booking(user: User): |
| 493 | + def process_booking(user: User) -> None: |
492 | 494 | reveal_type(User.objects) |
493 | 495 | reveal_type(User._default_manager) |
494 | 496 |
|
|
0 commit comments