Skip to content

Commit

Permalink
Typehint common dunder methods (#1238)
Browse files Browse the repository at this point in the history
* Typehint common dunder methods
* Additional hints: __hash__, __iter__, __copy__, __deepcopy__
* Can't use Self yet
  • Loading branch information
intgr authored Nov 8, 2022
1 parent 35847cc commit 2b095eb
Show file tree
Hide file tree
Showing 24 changed files with 55 additions and 57 deletions.
6 changes: 3 additions & 3 deletions django-stubs/contrib/auth/context_processors.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict
from typing import Any, Dict, Iterator

from django.http.request import HttpRequest

Expand All @@ -7,14 +7,14 @@ class PermLookupDict:
user: Any
def __init__(self, user: Any, app_label: str) -> None: ...
def __getitem__(self, perm_name: str) -> bool: ...
def __iter__(self) -> Any: ...
def __iter__(self) -> Iterator[Any]: ...
def __bool__(self) -> bool: ...

class PermWrapper:
user: Any = ...
def __init__(self, user: Any) -> None: ...
def __getitem__(self, app_label: str) -> PermLookupDict: ...
def __iter__(self) -> Any: ...
def __iter__(self) -> Iterator[Any]: ...
def __contains__(self, perm_name: Any) -> bool: ...

def auth(request: HttpRequest) -> Dict[str, Any]: ...
4 changes: 2 additions & 2 deletions django-stubs/contrib/gis/db/backends/base/adapter.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ class WKTAdapter:
wkt: Any = ...
srid: Any = ...
def __init__(self, geom: Any) -> None: ...
def __eq__(self, other: Any) -> Any: ...
def __hash__(self) -> Any: ...
def __eq__(self, other: Any) -> bool: ...
def __hash__(self) -> int: ...
4 changes: 2 additions & 2 deletions django-stubs/contrib/gis/db/backends/postgis/adapter.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class PostGISAdapter:
geography: Any = ...
def __init__(self, obj: Any, geography: bool = ...) -> None: ...
def __conform__(self, proto: Any) -> Any: ...
def __eq__(self, other: Any) -> Any: ...
def __hash__(self) -> Any: ...
def __eq__(self, other: Any) -> bool: ...
def __hash__(self) -> int: ...
def prepare(self, conn: Any) -> None: ...
def getquoted(self) -> Any: ...
2 changes: 1 addition & 1 deletion django-stubs/contrib/gis/gdal/datasource.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DataSource(GDALBase):
driver: Any = ...
def __init__(self, ds_input: Any, ds_driver: bool = ..., write: bool = ..., encoding: str = ...) -> None: ...
def __getitem__(self, index: Any) -> Any: ...
def __len__(self) -> Any: ...
def __len__(self) -> int: ...
@property
def layer_count(self) -> Any: ...
@property
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/gis/gdal/envelope.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class OGREnvelope(Structure): ...

class Envelope:
def __init__(self, *args: Any) -> None: ...
def __eq__(self, other: Any) -> Any: ...
def __eq__(self, other: Any) -> bool: ...
def expand_to_include(self, *args: Any) -> Any: ...
@property
def min_x(self) -> Any: ...
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/contrib/gis/gdal/feature.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class Feature(GDALBase):
ptr: Any = ...
def __init__(self, feat: Any, layer: Any) -> None: ...
def __getitem__(self, index: Any) -> Any: ...
def __len__(self) -> Any: ...
def __eq__(self, other: Any) -> Any: ...
def __len__(self) -> int: ...
def __eq__(self, other: Any) -> bool: ...
@property
def encoding(self) -> Any: ...
@property
Expand Down
1 change: 0 additions & 1 deletion django-stubs/contrib/gis/gdal/field.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ from django.contrib.gis.gdal.base import GDALBase as GDALBase

class Field(GDALBase):
ptr: Any = ...
__class__: Any = ...
def __init__(self, feat: Any, index: Any) -> None: ...
def as_double(self) -> Any: ...
def as_int(self, is_64: bool = ...) -> Any: ...
Expand Down
9 changes: 4 additions & 5 deletions django-stubs/contrib/gis/gdal/geometries.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class OGRGeometry(GDALBase):
destructor: Any = ...
ptr: Any = ...
srs: Any = ...
__class__: Any = ...
def __init__(self, geom_input: Any, srs: Optional[Any] = ...) -> None: ...
@classmethod
def from_bbox(cls, bbox: Any) -> Any: ...
Expand All @@ -18,7 +17,7 @@ class OGRGeometry(GDALBase):
def __and__(self, other: Any) -> Any: ...
def __sub__(self, other: Any) -> Any: ...
def __xor__(self, other: Any) -> Any: ...
def __eq__(self, other: Any) -> Any: ...
def __eq__(self, other: Any) -> bool: ...
@property
def dimension(self) -> Any: ...
coord_dim: Any = ...
Expand Down Expand Up @@ -95,7 +94,7 @@ class Point(OGRGeometry):

class LineString(OGRGeometry):
def __getitem__(self, index: Any) -> Any: ...
def __len__(self) -> Any: ...
def __len__(self) -> int: ...
@property
def tuple(self) -> Any: ...
coords: Any = ...
Expand All @@ -109,7 +108,7 @@ class LineString(OGRGeometry):
class LinearRing(LineString): ...

class Polygon(OGRGeometry):
def __len__(self) -> Any: ...
def __len__(self) -> int: ...
def __getitem__(self, index: Any) -> Any: ...
@property
def shell(self) -> Any: ...
Expand All @@ -124,7 +123,7 @@ class Polygon(OGRGeometry):

class GeometryCollection(OGRGeometry):
def __getitem__(self, index: Any) -> Any: ...
def __len__(self) -> Any: ...
def __len__(self) -> int: ...
def add(self, geom: Any) -> None: ...
@property
def point_count(self) -> Any: ...
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/gis/gdal/geomtype.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class OGRGeomType:
wkb25bit: int = ...
num: Any = ...
def __init__(self, type_input: Any) -> None: ...
def __eq__(self, other: Any) -> Any: ...
def __eq__(self, other: Any) -> bool: ...
@property
def name(self) -> Any: ...
@property
Expand Down
6 changes: 3 additions & 3 deletions django-stubs/contrib/gis/gdal/layer.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from typing import Any
from typing import Any, Iterator

from django.contrib.gis.gdal.base import GDALBase as GDALBase

class Layer(GDALBase):
ptr: Any = ...
def __init__(self, layer_ptr: Any, ds: Any) -> None: ...
def __getitem__(self, index: Any) -> Any: ...
def __iter__(self) -> Any: ...
def __len__(self) -> Any: ...
def __iter__(self) -> Iterator[Any]: ...
def __len__(self) -> int: ...
@property
def extent(self) -> Any: ...
@property
Expand Down
6 changes: 3 additions & 3 deletions django-stubs/contrib/gis/gdal/raster/band.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional
from typing import Any, Iterator, Optional

from django.contrib.gis.gdal.raster.base import GDALRasterBase as GDALRasterBase

Expand Down Expand Up @@ -40,6 +40,6 @@ class GDALBand(GDALRasterBase):
class BandList(list):
source: Any = ...
def __init__(self, source: Any) -> None: ...
def __iter__(self) -> Any: ...
def __len__(self) -> Any: ...
def __iter__(self) -> Iterator[Any]: ...
def __len__(self) -> int: ...
def __getitem__(self, index: Any) -> Any: ...
6 changes: 3 additions & 3 deletions django-stubs/contrib/gis/geos/collections.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Any
from typing import Any, Iterator

from django.contrib.gis.geos.geometry import GEOSGeometry as GEOSGeometry
from django.contrib.gis.geos.geometry import LinearGeometryMixin as LinearGeometryMixin

class GeometryCollection(GEOSGeometry):
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
def __iter__(self) -> Any: ...
def __len__(self) -> Any: ...
def __iter__(self) -> Iterator[Any]: ...
def __len__(self) -> int: ...
@property
def kml(self) -> Any: ...
@property
Expand Down
6 changes: 3 additions & 3 deletions django-stubs/contrib/gis/geos/coordseq.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Any
from typing import Any, Iterator

from django.contrib.gis.geos.base import GEOSBase as GEOSBase

class GEOSCoordSeq(GEOSBase):
ptr_type: Any = ...
def __init__(self, ptr: Any, z: bool = ...) -> None: ...
def __iter__(self) -> Any: ...
def __len__(self) -> Any: ...
def __iter__(self) -> Iterator[Any]: ...
def __len__(self) -> int: ...
def __getitem__(self, index: Any) -> Any: ...
def __setitem__(self, index: Any, value: Any) -> None: ...
def getOrdinate(self, dimension: Any, index: Any) -> Any: ...
Expand Down
13 changes: 7 additions & 6 deletions django-stubs/contrib/gis/geos/geometry.pyi
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
from typing import Any, Optional
from typing import Any, Optional, TypeVar

from django.contrib.gis.geometry import hex_regex as hex_regex # noqa: F401
from django.contrib.gis.geometry import json_regex as json_regex
from django.contrib.gis.geometry import wkt_regex as wkt_regex
from django.contrib.gis.geos.base import GEOSBase as GEOSBase
from django.contrib.gis.geos.mutable_list import ListMixin as ListMixin

_T = TypeVar("_T")

class GEOSGeometryBase(GEOSBase):
ptr_type: Any = ...
destructor: Any = ...
has_cs: bool = ...
__class__: Any = ...
def __init__(self, ptr: Any, cls: Any) -> None: ...
def __copy__(self) -> Any: ...
def __deepcopy__(self, memodict: Any) -> Any: ...
def __copy__(self: _T) -> _T: ...
def __deepcopy__(self: _T, memodict: Any) -> _T: ...
@staticmethod
def from_ewkt(ewkt: Any) -> Any: ...
@classmethod
def from_gml(cls, gml_string: Any) -> Any: ...
def __eq__(self, other: Any) -> Any: ...
def __hash__(self) -> Any: ...
def __eq__(self, other: Any) -> bool: ...
def __hash__(self) -> int: ...
def __or__(self, other: Any) -> Any: ...
def __and__(self, other: Any) -> Any: ...
def __sub__(self, other: Any) -> Any: ...
Expand Down
6 changes: 3 additions & 3 deletions django-stubs/contrib/gis/geos/linestring.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from typing import Any
from typing import Any, Iterator

from django.contrib.gis.geos.geometry import GEOSGeometry as GEOSGeometry
from django.contrib.gis.geos.geometry import LinearGeometryMixin as LinearGeometryMixin

class LineString(LinearGeometryMixin, GEOSGeometry):
has_cs: bool = ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
def __iter__(self) -> Any: ...
def __len__(self) -> Any: ...
def __iter__(self) -> Iterator[Any]: ...
def __len__(self) -> int: ...
@property
def tuple(self) -> Any: ...
coords: Any = ...
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/gis/geos/mutable_list.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ListMixin:
def __mul__(self, n: Any) -> Any: ...
def __rmul__(self, n: Any) -> Any: ...
def __imul__(self, n: Any) -> Any: ...
def __eq__(self, other: Any) -> Any: ...
def __eq__(self, other: Any) -> bool: ...
def __lt__(self, other: Any) -> Any: ...
def count(self, val: Any) -> Any: ...
def index(self, val: Any) -> Any: ...
Expand Down
6 changes: 3 additions & 3 deletions django-stubs/contrib/gis/geos/point.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional
from typing import Any, Iterator, Optional

from django.contrib.gis.geos.geometry import GEOSGeometry as GEOSGeometry

Expand All @@ -7,8 +7,8 @@ class Point(GEOSGeometry):
def __init__(
self, x: Optional[Any] = ..., y: Optional[Any] = ..., z: Optional[Any] = ..., srid: Optional[Any] = ...
) -> None: ...
def __iter__(self) -> Any: ...
def __len__(self) -> Any: ...
def __iter__(self) -> Iterator[Any]: ...
def __len__(self) -> int: ...
@property
def x(self) -> Any: ...
@x.setter
Expand Down
6 changes: 3 additions & 3 deletions django-stubs/contrib/gis/geos/polygon.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import Any
from typing import Any, Iterator

from django.contrib.gis.geos.geometry import GEOSGeometry as GEOSGeometry

class Polygon(GEOSGeometry):
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
def __iter__(self) -> Any: ...
def __len__(self) -> Any: ...
def __iter__(self) -> Iterator[Any]: ...
def __len__(self) -> int: ...
@classmethod
def from_bbox(cls, bbox: Any) -> Any: ...
@property
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/contrib/gis/measure.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MeasureBase:
def __init__(self, default_unit: Optional[Any] = ..., **kwargs: Any) -> None: ...
standard: Any = ...
def __getattr__(self, name: Any) -> Any: ...
def __eq__(self, other: Any) -> Any: ...
def __eq__(self, other: Any) -> bool: ...
def __lt__(self, other: Any) -> Any: ...
def __add__(self, other: Any) -> Any: ...
def __iadd__(self, other: Any) -> Any: ...
Expand All @@ -19,7 +19,7 @@ class MeasureBase:
def __rmul__(self, other: Any) -> Any: ...
def __truediv__(self, other: Any) -> Any: ...
def __itruediv__(self, other: Any) -> Any: ...
def __bool__(self) -> Any: ...
def __bool__(self) -> bool: ...
def default_units(self, kwargs: Any) -> Any: ...
@classmethod
def unit_attname(cls, unit_str: Any) -> Any: ...
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/db/backends/oracle/base.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from contextlib import contextmanager
from typing import Any, Generator, Optional, Type
from typing import Any, Generator, Iterator, Optional, Type

from django.db.backends.base.base import BaseDatabaseWrapper as BaseDatabaseWrapper

Expand Down Expand Up @@ -74,4 +74,4 @@ class FormatStylePlaceholderCursor:
def var(self, *args: Any) -> Any: ...
def arrayvar(self, *args: Any) -> Any: ...
def __getattr__(self, attr: Any) -> Any: ...
def __iter__(self) -> Any: ...
def __iter__(self) -> Iterator[Any]: ...
4 changes: 2 additions & 2 deletions django-stubs/template/response.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import functools
from http.cookies import SimpleCookie
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
from typing import Any, Callable, Dict, Iterator, List, Optional, Sequence, Tuple, Union

from django.core.handlers.wsgi import WSGIRequest
from django.http import HttpResponse
Expand Down Expand Up @@ -41,7 +41,7 @@ class SimpleTemplateResponse(HttpResponse):
def render(self) -> SimpleTemplateResponse: ...
@property
def is_rendered(self) -> bool: ...
def __iter__(self) -> Any: ...
def __iter__(self) -> Iterator[Any]: ...

class TemplateResponse(SimpleTemplateResponse):
client: Client
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/template/utils.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Tuple
from typing import Any, Dict, Iterator, List, Tuple

from django.core.exceptions import ImproperlyConfigured
from django.template.backends.base import BaseEngine
Expand All @@ -10,7 +10,7 @@ class EngineHandler:
@property
def templates(self) -> Dict[str, Any]: ...
def __getitem__(self, alias: str) -> BaseEngine: ...
def __iter__(self) -> Any: ...
def __iter__(self) -> Iterator[Any]: ...
def all(self) -> List[BaseEngine]: ...

def get_app_template_dirs(dirname: str) -> Tuple: ...
4 changes: 2 additions & 2 deletions django-stubs/urls/resolvers.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from types import ModuleType
from typing import Any, Callable, Dict, List, Optional, Pattern, Sequence, Tuple, Type, Union, overload
from typing import Any, Callable, Dict, Iterator, List, Optional, Pattern, Sequence, Tuple, Type, Union, overload

from django.core.checks.messages import CheckMessage
from django.urls import _AnyURL
Expand Down Expand Up @@ -32,7 +32,7 @@ class ResolverMatch:
) -> None: ...
def __getitem__(self, index: int) -> Any: ...
# for tuple unpacking
def __iter__(self) -> Any: ...
def __iter__(self) -> Iterator[Any]: ...

def get_resolver(urlconf: Optional[str] = ...) -> URLResolver: ...
def get_ns_resolver(ns_pattern: str, resolver: URLResolver, converters: Tuple) -> URLResolver: ...
Expand Down
1 change: 0 additions & 1 deletion django-stubs/utils/functional.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class LazyObject:
__bytes__: Callable = ...
__bool__: Callable = ...
__dir__: Callable = ...
__class__: Any = ...
__ne__: Callable = ...
__hash__: Callable = ...
__getitem__: Callable = ...
Expand Down

0 comments on commit 2b095eb

Please sign in to comment.