mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-07 04:34:29 +08:00
do not emit error, if attribute does not exist
This commit is contained in:
@@ -176,3 +176,5 @@ def process_model_class(ctx: ClassDefContext) -> None:
|
|||||||
set_fieldname_attrs_for_related_fields(ctx)
|
set_fieldname_attrs_for_related_fields(ctx)
|
||||||
add_int_id_attribute_if_primary_key_true_is_not_present(ctx)
|
add_int_id_attribute_if_primary_key_true_is_not_present(ctx)
|
||||||
set_objects_queryset_to_model_class(ctx)
|
set_objects_queryset_to_model_class(ctx)
|
||||||
|
|
||||||
|
ctx.cls.info.fallback_to_any = True
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ def add_settings_to_django_conf_object(ctx: ClassDefContext,
|
|||||||
context.set_line(sym.node)
|
context.set_line(sym.node)
|
||||||
api.msg.report(f"Need type annotation for '{sym.node.name()}'", context,
|
api.msg.report(f"Need type annotation for '{sym.node.name()}'", context,
|
||||||
severity='error', file=module_file.path)
|
severity='error', file=module_file.path)
|
||||||
|
ctx.cls.info.fallback_to_any = True
|
||||||
|
|
||||||
|
|
||||||
class DjangoConfSettingsInitializerHook(object):
|
class DjangoConfSettingsInitializerHook(object):
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ class User(models.Model):
|
|||||||
reveal_type(User().my_pk) # E: Revealed type is 'builtins.int'
|
reveal_type(User().my_pk) # E: Revealed type is 'builtins.int'
|
||||||
reveal_type(User().id) # E: Revealed type is 'Any'
|
reveal_type(User().id) # E: Revealed type is 'Any'
|
||||||
[out]
|
[out]
|
||||||
main:7: error: "User" has no attribute "id"
|
|
||||||
|
|
||||||
[CASE test_meta_nested_class_allows_subclassing_in_multiple_inheritance]
|
[CASE test_meta_nested_class_allows_subclassing_in_multiple_inheritance]
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|||||||
@@ -110,7 +110,6 @@ class View(models.Model):
|
|||||||
reveal_type(View().app.views) # E: Revealed type is 'django.db.models.query.QuerySet[main.View]'
|
reveal_type(View().app.views) # E: Revealed type is 'django.db.models.query.QuerySet[main.View]'
|
||||||
reveal_type(View().app.unknown) # E: Revealed type is 'Any'
|
reveal_type(View().app.unknown) # E: Revealed type is 'Any'
|
||||||
[out]
|
[out]
|
||||||
main:7: error: "App" has no attribute "unknown"
|
|
||||||
|
|
||||||
[file myapp/__init__.py]
|
[file myapp/__init__.py]
|
||||||
[file myapp/models.py]
|
[file myapp/models.py]
|
||||||
|
|||||||
@@ -40,8 +40,6 @@ reveal_type(settings.REGISTRY) # E: Revealed type is 'Union[main.Class, None]'
|
|||||||
reveal_type(settings.LIST) # E: Revealed type is 'Any'
|
reveal_type(settings.LIST) # E: Revealed type is 'Any'
|
||||||
reveal_type(settings.BASE_LIST) # E: Revealed type is 'Any'
|
reveal_type(settings.BASE_LIST) # E: Revealed type is 'Any'
|
||||||
[out]
|
[out]
|
||||||
main:5: error: "LazySettings" has no attribute "LIST"
|
|
||||||
main:6: error: "LazySettings" has no attribute "BASE_LIST"
|
|
||||||
mysettings:4: error: Need type annotation for 'LIST'
|
mysettings:4: error: Need type annotation for 'LIST'
|
||||||
base:6: error: Need type annotation for 'BASE_LIST'
|
base:6: error: Need type annotation for 'BASE_LIST'
|
||||||
|
|
||||||
@@ -80,3 +78,10 @@ MYSETTING = 1122
|
|||||||
REGISTRY: Optional['Class'] = None
|
REGISTRY: Optional['Class'] = None
|
||||||
LIST: List[str] = ['1', '2']
|
LIST: List[str] = ['1', '2']
|
||||||
|
|
||||||
|
[CASE allow_calls_to_nonexistent_members_for_now]
|
||||||
|
from django.conf import settings
|
||||||
|
reveal_type(settings.NOT_EXISTING) # E: Revealed type is 'Any'
|
||||||
|
|
||||||
|
[env DJANGO_SETTINGS_MODULE=mysettings]
|
||||||
|
[file mysettings.py]
|
||||||
|
[out]
|
||||||
|
|||||||
Reference in New Issue
Block a user