Skip to content

Commit 4dd2e42

Browse files
committed
code cleanups, disable monkeypatches, move to add_additional_deps
1 parent 13d1901 commit 4dd2e42

File tree

18 files changed

+295
-436
lines changed

18 files changed

+295
-436
lines changed

django-stubs/conf/__init__.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ from typing import Any
22

33
from django.utils.functional import LazyObject
44

5+
# explicit dependency on standard settings to make it loaded
6+
from . import global_settings
7+
58
ENVIRONMENT_VARIABLE: str = ...
69

710
# required for plugin to be able to distinguish this specific instance of LazySettings from others
8-
class _DjangoConfLazyObject(LazyObject): ...
11+
class _DjangoConfLazyObject(LazyObject):
12+
def __getattr__(self, item: Any) -> Any: ...
913

1014
class LazySettings(_DjangoConfLazyObject):
1115
configured: bool

django-stubs/conf/global_settings.pyi

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ by the DJANGO_SETTINGS_MODULE environment variable.
55

66
# This is defined here as a do-nothing function because we can't import
77
# django.utils.translation -- that module depends on the settings.
8-
from typing import Any, Dict, List, Optional, Pattern, Tuple, Protocol, Union, Callable, TYPE_CHECKING, Sequence
8+
from typing import Any, Dict, List, Optional, Pattern, Protocol, Sequence, Tuple, Union
99

1010
####################
1111
# CORE #
1212
####################
13-
if TYPE_CHECKING:
14-
from django.db.models.base import Model
15-
1613
DEBUG: bool = ...
1714

1815
# Whether the framework should propagate raw exceptions rather than catching
@@ -153,7 +150,7 @@ FORCE_SCRIPT_NAME = None
153150
# ]
154151
DISALLOWED_USER_AGENTS: List[Pattern] = ...
155152

156-
ABSOLUTE_URL_OVERRIDES: Dict[str, Callable[[Model], str]] = ...
153+
ABSOLUTE_URL_OVERRIDES: Dict[str, Any] = ...
157154

158155
# List of compiled regular expression objects representing URLs that need not
159156
# be reported by BrokenLinkEmailsMiddleware. Here are a few examples:

mypy_django_plugin/helpers.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
from mypy.mro import calculate_mro
66
from mypy.nodes import (
7-
AssignmentStmt, ClassDef, Expression, ImportedName, Lvalue, MypyFile, NameExpr, SymbolNode, TypeInfo,
8-
SymbolTable, SymbolTableNode, Block, GDEF, MDEF, Var)
7+
GDEF, MDEF, AssignmentStmt, Block, CallExpr, ClassDef, Expression, ImportedName, Lvalue, MypyFile, NameExpr,
8+
SymbolNode, SymbolTable, SymbolTableNode, TypeInfo, Var,
9+
)
910
from mypy.plugin import FunctionContext, MethodContext
1011
from mypy.types import (
11-
AnyType, Instance, NoneTyp, Type, TypeOfAny, TypeVarType, UnionType,
12-
TupleType, TypedDictType)
12+
AnyType, Instance, NoneTyp, TupleType, Type, TypedDictType, TypeOfAny, TypeVarType, UnionType,
13+
)
1314

1415
if typing.TYPE_CHECKING:
1516
from mypy.checker import TypeChecker
@@ -386,3 +387,15 @@ def get_private_descriptor_type(type_info: TypeInfo, private_field_name: str, is
386387
descriptor_type = make_optional(descriptor_type)
387388
return descriptor_type
388389
return AnyType(TypeOfAny.unannotated)
390+
391+
392+
def iter_over_classdefs(module_file: MypyFile) -> typing.Iterator[ClassDef]:
393+
for defn in module_file.defs:
394+
if isinstance(defn, ClassDef):
395+
yield defn
396+
397+
398+
def iter_call_assignments(klass: ClassDef) -> typing.Iterator[typing.Tuple[Lvalue, CallExpr]]:
399+
for lvalue, rvalue in iter_over_assignments(klass):
400+
if isinstance(rvalue, CallExpr):
401+
yield lvalue, rvalue

mypy_django_plugin/lookups.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import dataclasses
2-
from typing import Union, List
1+
from typing import List, Union
32

3+
import dataclasses
44
from mypy.nodes import TypeInfo
55
from mypy.plugin import CheckerPluginInterface
6-
from mypy.types import Type, Instance
6+
from mypy.types import Instance, Type
77

88
from mypy_django_plugin import helpers
99

0 commit comments

Comments
 (0)