mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-08 04:54:48 +08:00
Merge branch 'master' into queryset_in_bulk
This commit is contained in:
@@ -1,28 +1,30 @@
|
||||
[CASE missing_settings_ignored_flag]
|
||||
[env MYPY_DJANGO_CONFIG=${MYPY_CWD}/mypy_django.ini]
|
||||
[disable_cache]
|
||||
from django.conf import settings
|
||||
reveal_type(settings.NO_SUCH_SETTING) # E: Revealed type is 'Any'
|
||||
|
||||
[env MYPY_DJANGO_CONFIG=${MYPY_CWD}/mypy_django.ini]
|
||||
|
||||
[file mypy_django.ini]
|
||||
[[mypy_django_plugin]
|
||||
ignore_missing_settings = True
|
||||
[out]
|
||||
[/CASE]
|
||||
|
||||
[CASE django_settings_via_config_file]
|
||||
[env MYPY_DJANGO_CONFIG=${MYPY_CWD}/mypy_django.ini]
|
||||
[disable_cache]
|
||||
from django.conf import settings
|
||||
reveal_type(settings.MY_SETTING) # E: Revealed type is 'builtins.int'
|
||||
|
||||
[env MYPY_DJANGO_CONFIG=${MYPY_CWD}/mypy_django.ini]
|
||||
[file mypy_django.ini]
|
||||
[[mypy_django_plugin]
|
||||
django_settings = mysettings
|
||||
|
||||
[file mysettings.py]
|
||||
MY_SETTING: int = 1
|
||||
[out]
|
||||
[/CASE]
|
||||
|
||||
[CASE mypy_django_ini_in_current_directory_is_a_default]
|
||||
[disable_cache]
|
||||
from django.conf import settings
|
||||
reveal_type(settings.MY_SETTING) # E: Revealed type is 'builtins.int'
|
||||
|
||||
@@ -32,4 +34,4 @@ django_settings = mysettings
|
||||
|
||||
[file mysettings.py]
|
||||
MY_SETTING: int = 1
|
||||
[out]
|
||||
[/CASE]
|
||||
|
||||
@@ -7,6 +7,7 @@ class User(models.Model):
|
||||
|
||||
user = User()
|
||||
reveal_type(user.array) # E: Revealed type is 'builtins.list*[Any]'
|
||||
[/CASE]
|
||||
|
||||
[CASE array_field_base_field_parsed_into_generic_typevar]
|
||||
from django.db import models
|
||||
@@ -19,6 +20,7 @@ class User(models.Model):
|
||||
user = User()
|
||||
reveal_type(user.members) # E: Revealed type is 'builtins.list*[builtins.int]'
|
||||
reveal_type(user.members_as_text) # E: Revealed type is 'builtins.list*[builtins.str]'
|
||||
[/CASE]
|
||||
|
||||
[CASE test_model_fields_classes_present_as_primitives]
|
||||
from django.db import models
|
||||
@@ -36,6 +38,7 @@ reveal_type(user.small_int) # E: Revealed type is 'builtins.int*'
|
||||
reveal_type(user.name) # E: Revealed type is 'builtins.str*'
|
||||
reveal_type(user.slug) # E: Revealed type is 'builtins.str*'
|
||||
reveal_type(user.text) # E: Revealed type is 'builtins.str*'
|
||||
[/CASE]
|
||||
|
||||
[CASE test_model_field_classes_from_existing_locations]
|
||||
from django.db import models
|
||||
@@ -51,6 +54,7 @@ booking = Booking()
|
||||
reveal_type(booking.id) # E: Revealed type is 'builtins.int*'
|
||||
reveal_type(booking.time_range) # E: Revealed type is 'Any'
|
||||
reveal_type(booking.some_decimal) # E: Revealed type is 'decimal.Decimal*'
|
||||
[/CASE]
|
||||
|
||||
[CASE test_add_id_field_if_no_primary_key_defined]
|
||||
from django.db import models
|
||||
@@ -59,6 +63,7 @@ class User(models.Model):
|
||||
pass
|
||||
|
||||
reveal_type(User().id) # E: Revealed type is 'builtins.int'
|
||||
[/CASE]
|
||||
|
||||
[CASE test_do_not_add_id_if_field_with_primary_key_True_defined]
|
||||
from django.db import models
|
||||
@@ -68,7 +73,7 @@ class User(models.Model):
|
||||
|
||||
reveal_type(User().my_pk) # E: Revealed type is 'builtins.int*'
|
||||
reveal_type(User().id) # E: Revealed type is 'Any'
|
||||
[out]
|
||||
[/CASE]
|
||||
|
||||
[CASE test_meta_nested_class_allows_subclassing_in_multiple_inheritance]
|
||||
from typing import Any
|
||||
@@ -84,7 +89,7 @@ class Mixin2(models.Model):
|
||||
|
||||
class User(Mixin1, Mixin2):
|
||||
pass
|
||||
[out]
|
||||
[/CASE]
|
||||
|
||||
[CASE test_inheritance_from_abstract_model_does_not_fail_if_field_with_id_exists]
|
||||
from django.db import models
|
||||
@@ -93,7 +98,7 @@ class Abstract(models.Model):
|
||||
abstract = True
|
||||
class User(Abstract):
|
||||
id = models.AutoField(primary_key=True)
|
||||
[out]
|
||||
[/CASE]
|
||||
|
||||
[CASE standard_it_from_parent_model_could_be_overridden_with_non_integer_field_in_child_model]
|
||||
from django.db import models
|
||||
@@ -103,11 +108,11 @@ class ParentModel(models.Model):
|
||||
class MyModel(ParentModel):
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
reveal_type(MyModel().id) # E: Revealed type is 'uuid.UUID*'
|
||||
[out]
|
||||
[/CASE]
|
||||
|
||||
[CASE blank_for_charfield_is_the_same_as_null]
|
||||
from django.db import models
|
||||
class MyModel(models.Model):
|
||||
text = models.CharField(max_length=30, blank=True)
|
||||
MyModel(text=None)
|
||||
[out]
|
||||
[/CASE]
|
||||
|
||||
@@ -191,6 +191,8 @@ class Profile(models.Model):
|
||||
from django.db import models
|
||||
class App(models.Model):
|
||||
owner = models.ForeignKey(to='myapp.User', on_delete=models.CASCADE, related_name='apps')
|
||||
[disable_cache]
|
||||
[/CASE]
|
||||
|
||||
[CASE many_to_many_field_converts_to_queryset_of_model_type]
|
||||
from django.db import models
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
[CASE test_settings_are_parsed_into_django_conf_settings]
|
||||
[env DJANGO_SETTINGS_MODULE=mysettings]
|
||||
[disable_cache]
|
||||
from django.conf import settings
|
||||
|
||||
reveal_type(settings.ROOT_DIR) # E: Revealed type is 'builtins.str'
|
||||
@@ -6,7 +8,6 @@ reveal_type(settings.APPS_DIR) # E: Revealed type is 'pathlib.Path'
|
||||
reveal_type(settings.OBJ) # E: Revealed type is 'django.utils.functional.LazyObject'
|
||||
reveal_type(settings.NUMBERS) # E: Revealed type is 'builtins.list[builtins.str]'
|
||||
reveal_type(settings.DICT) # E: Revealed type is 'builtins.dict[Any, Any]'
|
||||
[env DJANGO_SETTINGS_MODULE=mysettings]
|
||||
[file base.py]
|
||||
from pathlib import Path
|
||||
ROOT_DIR = '/etc'
|
||||
@@ -18,14 +19,16 @@ NUMBERS = ['one', 'two']
|
||||
DICT = {} # type: ignore
|
||||
from django.utils.functional import LazyObject
|
||||
OBJ = LazyObject()
|
||||
[/CASE]
|
||||
|
||||
[CASE test_settings_could_be_defined_in_different_module_and_imported_with_star]
|
||||
[env DJANGO_SETTINGS_MODULE=mysettings]
|
||||
[disable_cache]
|
||||
from django.conf import settings
|
||||
|
||||
reveal_type(settings.ROOT_DIR) # E: Revealed type is 'pathlib.Path'
|
||||
reveal_type(settings.SETUP) # E: Revealed type is 'builtins.int'
|
||||
reveal_type(settings.DATABASES) # E: Revealed type is 'builtins.dict[builtins.str, builtins.str]'
|
||||
[env DJANGO_SETTINGS_MODULE=mysettings]
|
||||
[file mysettings.py]
|
||||
from local import *
|
||||
DATABASES = {'default': 'mydb'}
|
||||
@@ -36,24 +39,25 @@ SETUP = 3
|
||||
from pathlib import Path
|
||||
|
||||
ROOT_DIR = Path(__file__)
|
||||
[/CASE]
|
||||
|
||||
[CASE global_settings_are_always_loaded]
|
||||
from django.conf import settings
|
||||
|
||||
reveal_type(settings.AUTH_USER_MODEL) # E: Revealed type is 'builtins.str'
|
||||
reveal_type(settings.AUTHENTICATION_BACKENDS) # E: Revealed type is 'typing.Sequence[builtins.str]'
|
||||
[out]
|
||||
[/CASE]
|
||||
|
||||
[CASE test_circular_dependency_in_settings_works_if_settings_have_annotations]
|
||||
[env DJANGO_SETTINGS_MODULE=mysettings]
|
||||
[disable_cache]
|
||||
from django.conf import settings
|
||||
class Class:
|
||||
pass
|
||||
reveal_type(settings.MYSETTING) # E: Revealed type is 'builtins.int'
|
||||
reveal_type(settings.REGISTRY) # E: Revealed type is 'Union[main.Class, None]'
|
||||
reveal_type(settings.LIST) # E: Revealed type is 'builtins.list[builtins.str]'
|
||||
[out]
|
||||
|
||||
[env DJANGO_SETTINGS_MODULE=mysettings]
|
||||
[file mysettings.py]
|
||||
from typing import TYPE_CHECKING, Optional, List
|
||||
|
||||
@@ -63,13 +67,16 @@ if TYPE_CHECKING:
|
||||
MYSETTING = 1122
|
||||
REGISTRY: Optional['Class'] = None
|
||||
LIST: List[str] = ['1', '2']
|
||||
[/CASE]
|
||||
|
||||
[CASE fail_if_there_is_no_setting]
|
||||
from django.conf import settings
|
||||
reveal_type(settings.NOT_EXISTING)
|
||||
|
||||
[env DJANGO_SETTINGS_MODULE=mysettings]
|
||||
[disable_cache]
|
||||
[file mysettings.py]
|
||||
[out]
|
||||
main:2: error: Revealed type is 'Any'
|
||||
main:2: error: "LazySettings" has no attribute "NOT_EXISTING"
|
||||
main:2: error: "LazySettings" has no attribute "NOT_EXISTING"
|
||||
[/CASE]
|
||||
@@ -11,9 +11,11 @@ reveal_type(get_object_or_404(MyModel.objects.get_queryset())) # E: Revealed ty
|
||||
reveal_type(get_list_or_404(MyModel)) # E: Revealed type is 'builtins.list[main.MyModel*]'
|
||||
reveal_type(get_list_or_404(MyModel.objects)) # E: Revealed type is 'builtins.list[main.MyModel*]'
|
||||
reveal_type(get_list_or_404(MyModel.objects.get_queryset())) # E: Revealed type is 'builtins.list[main.MyModel*]'
|
||||
[out]
|
||||
[/CASE]
|
||||
|
||||
[CASE get_user_model_returns_proper_class]
|
||||
[env DJANGO_SETTINGS_MODULE=mysettings]
|
||||
[disable_cache]
|
||||
from typing import TYPE_CHECKING
|
||||
if TYPE_CHECKING:
|
||||
from myapp.models import MyUser
|
||||
@@ -22,7 +24,6 @@ from django.contrib.auth import get_user_model
|
||||
UserModel = get_user_model()
|
||||
reveal_type(UserModel.objects) # E: Revealed type is 'django.db.models.manager.Manager[myapp.models.MyUser]'
|
||||
|
||||
[env DJANGO_SETTINGS_MODULE=mysettings]
|
||||
[file mysettings.py]
|
||||
INSTALLED_APPS = ('myapp',)
|
||||
AUTH_USER_MODEL = 'myapp.MyUser'
|
||||
@@ -32,15 +33,16 @@ AUTH_USER_MODEL = 'myapp.MyUser'
|
||||
from django.db import models
|
||||
class MyUser(models.Model):
|
||||
pass
|
||||
[out]
|
||||
[/CASE]
|
||||
|
||||
[CASE return_type_model_and_show_error_if_model_not_yet_imported]
|
||||
[env DJANGO_SETTINGS_MODULE=mysettings]
|
||||
[disable_cache]
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
UserModel = get_user_model()
|
||||
reveal_type(UserModel.objects)
|
||||
|
||||
[env DJANGO_SETTINGS_MODULE=mysettings]
|
||||
[file mysettings.py]
|
||||
INSTALLED_APPS = ('myapp',)
|
||||
AUTH_USER_MODEL = 'myapp.MyUser'
|
||||
@@ -53,4 +55,5 @@ class MyUser(models.Model):
|
||||
[out]
|
||||
main:3: error: "myapp.MyUser" model class is not imported so far. Try to import it (under if TYPE_CHECKING) at the beginning of the current file
|
||||
main:4: error: Revealed type is 'Any'
|
||||
main:4: error: "Type[Model]" has no attribute "objects"
|
||||
main:4: error: "Type[Model]" has no attribute "objects"
|
||||
[/CASE]
|
||||
|
||||
Reference in New Issue
Block a user