mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-11 22:41:55 +08:00
add GenericForeignKey support, remove some false-positives
This commit is contained in:
@@ -8,8 +8,8 @@ from django.db.models.base import Model
|
||||
from .config import AppConfig
|
||||
|
||||
class Apps:
|
||||
all_models: 'Dict[str, OrderedDict[str, Type[Model]]]' = ...
|
||||
app_configs: 'OrderedDict[str, AppConfig]' = ...
|
||||
all_models: "Dict[str, OrderedDict[str, Type[Model]]]" = ...
|
||||
app_configs: "OrderedDict[str, AppConfig]" = ...
|
||||
stored_app_configs: List[Any] = ...
|
||||
apps_ready: bool = ...
|
||||
ready_event: threading.Event = ...
|
||||
|
||||
@@ -7,6 +7,7 @@ from django.db.models.fields.related import ForeignObject
|
||||
from django.db.models.fields.related_descriptors import ReverseManyToOneDescriptor
|
||||
from django.db.models.fields.reverse_related import ForeignObjectRel
|
||||
|
||||
from django.db.models.expressions import Combinable
|
||||
from django.db.models.fields import Field, PositiveIntegerField
|
||||
from django.db.models.fields.mixins import FieldCacheMixin
|
||||
from django.db.models.query import QuerySet
|
||||
@@ -14,6 +15,10 @@ from django.db.models.query_utils import FilteredRelation, PathInfo
|
||||
from django.db.models.sql.where import WhereNode
|
||||
|
||||
class GenericForeignKey(FieldCacheMixin):
|
||||
# django-stubs implementation only fields
|
||||
_pyi_private_set_type: Union[Any, Combinable]
|
||||
_pyi_private_get_type: Any
|
||||
# attributes
|
||||
auto_created: bool = ...
|
||||
concrete: bool = ...
|
||||
editable: bool = ...
|
||||
@@ -44,10 +49,8 @@ class GenericForeignKey(FieldCacheMixin):
|
||||
def get_prefetch_queryset(
|
||||
self, instances: Union[List[Model], QuerySet], queryset: Optional[QuerySet] = ...
|
||||
) -> Tuple[List[Model], Callable, Callable, bool, str, bool]: ...
|
||||
def __get__(
|
||||
self, instance: Optional[Model], cls: Type[Model] = ...
|
||||
) -> Optional[Union[GenericForeignKey, Model]]: ...
|
||||
def __set__(self, instance: Model, value: Optional[Model]) -> None: ...
|
||||
def __get__(self, instance: Optional[Model], cls: Type[Model] = ...) -> Optional[Any]: ...
|
||||
def __set__(self, instance: Model, value: Optional[Any]) -> None: ...
|
||||
|
||||
class GenericRel(ForeignObjectRel):
|
||||
field: GenericRelation
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
from typing import Any, Dict, List, Optional, Tuple, Union
|
||||
from typing import Any, Dict, List, Tuple, Union
|
||||
|
||||
from django.core.management.base import BaseCommand as BaseCommand, CommandError as CommandError
|
||||
from .base import BaseCommand as BaseCommand, CommandError as CommandError
|
||||
|
||||
def find_commands(management_dir: str) -> List[str]: ...
|
||||
def load_command_class(app_name: str, name: str) -> BaseCommand: ...
|
||||
def get_commands() -> Dict[str, str]: ...
|
||||
def call_command(command_name: Union[Tuple[str], BaseCommand, str], *args: Any, **options: Any) -> Optional[str]: ...
|
||||
def call_command(command_name: Union[Tuple[str], BaseCommand, str], *args: Any, **options: Any) -> str: ...
|
||||
|
||||
class ManagementUtility:
|
||||
argv: List[str] = ...
|
||||
|
||||
@@ -11,6 +11,7 @@ from .base import (
|
||||
SerializationError as SerializationError,
|
||||
DeserializationError as DeserializationError,
|
||||
M2MDeserializationError as M2MDeserializationError,
|
||||
DeserializedObject,
|
||||
)
|
||||
|
||||
BUILTIN_SERIALIZERS: Any
|
||||
@@ -27,10 +28,8 @@ def get_serializer(format: str) -> Union[Type[Serializer], BadSerializer]: ...
|
||||
def get_serializer_formats() -> List[str]: ...
|
||||
def get_public_serializer_formats() -> List[str]: ...
|
||||
def get_deserializer(format: str) -> Union[Callable, Type[Deserializer]]: ...
|
||||
def serialize(
|
||||
format: str, queryset: Union[Iterator[Any], List[Model], QuerySet], **options: Any
|
||||
) -> Optional[Union[bytes, str]]: ...
|
||||
def deserialize(format: str, stream_or_string: Any, **options: Any) -> Union[Iterator[Any], Deserializer]: ...
|
||||
def serialize(format: str, queryset: Iterable[Model], **options: Any) -> Optional[Union[bytes, str]]: ...
|
||||
def deserialize(format: str, stream_or_string: Any, **options: Any) -> Iterator[DeserializedObject]: ...
|
||||
def sort_dependencies(
|
||||
app_list: Union[Iterable[Tuple[AppConfig, None]], Iterable[Tuple[str, Iterable[Type[Model]]]]]
|
||||
) -> List[Type[Model]]: ...
|
||||
|
||||
@@ -70,8 +70,8 @@ class Deserializer:
|
||||
def __next__(self) -> None: ...
|
||||
|
||||
class DeserializedObject:
|
||||
object: Model = ...
|
||||
m2m_data: Dict[Any, Any] = ...
|
||||
object: Any = ...
|
||||
m2m_data: Dict[str, List[int]] = ...
|
||||
def __init__(self, obj: Model, m2m_data: Optional[Dict[str, List[int]]] = ...) -> None: ...
|
||||
def save(self, save_m2m: bool = ..., using: Optional[str] = ..., **kwargs: Any) -> None: ...
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ from django.core.checks.messages import CheckMessage
|
||||
|
||||
from django.db.models.options import Options
|
||||
|
||||
|
||||
class ModelBase(type): ...
|
||||
|
||||
_Self = TypeVar("_Self", bound="Model")
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import decimal
|
||||
import uuid
|
||||
from datetime import date, datetime, time, timedelta
|
||||
from typing import Any, Callable, Dict, Generic, Iterable, Optional, Tuple, Type, TypeVar, Union, Sequence
|
||||
from typing import Any, Callable, Dict, Generic, Iterable, Optional, Tuple, Type, TypeVar, Union, Sequence, List
|
||||
|
||||
from django.core import checks
|
||||
|
||||
from django.db.models import Model
|
||||
from django.core.exceptions import FieldDoesNotExist as FieldDoesNotExist
|
||||
@@ -41,6 +43,8 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]):
|
||||
null: bool = ...
|
||||
editable: bool = ...
|
||||
choices: Optional[_FieldChoices] = ...
|
||||
db_column: Optional[str]
|
||||
column: str
|
||||
def __init__(
|
||||
self,
|
||||
verbose_name: Optional[Union[str, bytes]] = ...,
|
||||
@@ -86,6 +90,7 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]):
|
||||
) -> Sequence[Union[_Choice, _ChoiceNamedGroup]]: ...
|
||||
def has_default(self) -> bool: ...
|
||||
def get_default(self) -> Any: ...
|
||||
def check(self, **kwargs: Any) -> List[checks.Error]: ...
|
||||
|
||||
class IntegerField(Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[float, int, str, Combinable]
|
||||
|
||||
@@ -108,4 +108,6 @@ class Options:
|
||||
def get_ancestor_link(self, ancestor: Type[Model]) -> Optional[OneToOneField]: ...
|
||||
def get_path_to_parent(self, parent: Type[Model]) -> List[PathInfo]: ...
|
||||
def get_path_from_parent(self, parent: Type[Model]) -> List[PathInfo]: ...
|
||||
def get_fields(self, include_parents: bool = ..., include_hidden: bool = ...) -> List[Union[Field, ForeignObjectRel]]: ...
|
||||
def get_fields(
|
||||
self, include_parents: bool = ..., include_hidden: bool = ...
|
||||
) -> List[Union[Field, ForeignObjectRel]]: ...
|
||||
|
||||
@@ -121,9 +121,11 @@ class QuerySet(Generic[_T, _Row], Collection[_Row], Sized):
|
||||
def select_for_update(self, nowait: bool = ..., skip_locked: bool = ..., of: Tuple = ...) -> QuerySet[_T, _Row]: ...
|
||||
def select_related(self, *fields: Any) -> QuerySet[_T, _Row]: ...
|
||||
def prefetch_related(self, *lookups: Any) -> QuerySet[_T, _Row]: ...
|
||||
def annotate(self, *args: Any, **kwargs: Any) -> QuerySet[_T, _Row]: ...
|
||||
# TODO: return type
|
||||
def annotate(self, *args: Any, **kwargs: Any) -> QuerySet[Any, Any]: ...
|
||||
def order_by(self, *field_names: Any) -> QuerySet[_T, _Row]: ...
|
||||
def distinct(self, *field_names: Any) -> QuerySet[_T, _Row]: ...
|
||||
# extra() return type won't be supported any time soon
|
||||
def extra(
|
||||
self,
|
||||
select: Optional[Dict[str, Any]] = ...,
|
||||
@@ -132,7 +134,7 @@ class QuerySet(Generic[_T, _Row], Collection[_Row], Sized):
|
||||
tables: Optional[List[str]] = ...,
|
||||
order_by: Optional[Sequence[str]] = ...,
|
||||
select_params: Optional[Sequence[Any]] = ...,
|
||||
) -> QuerySet[_T, _Row]: ...
|
||||
) -> QuerySet[Any, Any]: ...
|
||||
def reverse(self) -> QuerySet[_T, _Row]: ...
|
||||
def defer(self, *fields: Any) -> QuerySet[_T, _Row]: ...
|
||||
def only(self, *fields: Any) -> QuerySet[_T, _Row]: ...
|
||||
|
||||
@@ -39,10 +39,10 @@ ungettext = ngettext
|
||||
def pgettext(context: str, message: str) -> str: ...
|
||||
def npgettext(context: str, singular: str, plural: str, number: int) -> str: ...
|
||||
|
||||
gettext_lazy: Any
|
||||
gettext_lazy: Callable[[str], str]
|
||||
|
||||
ugettext_lazy: Any
|
||||
pgettext_lazy: Any
|
||||
ugettext_lazy: Callable[[str], str]
|
||||
pgettext_lazy: Callable[[str], str]
|
||||
|
||||
def ngettext_lazy(singular: Any, plural: Any, number: Optional[Any] = ...): ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user