mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-01-01 09:03:23 +08:00
Improve __enter__ & constructor methods (#7114)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from _typeshed import SupportsRead, SupportsWrite
|
||||
from _typeshed import Self, SupportsRead, SupportsWrite
|
||||
from collections.abc import Iterable, Iterator, MutableMapping
|
||||
from pathlib import Path
|
||||
from typing import Any, Callable, ClassVar, Protocol, Sequence, SupportsBytes, Union
|
||||
@@ -118,7 +118,7 @@ class Image:
|
||||
def height(self) -> int: ...
|
||||
@property
|
||||
def size(self) -> tuple[int, int]: ...
|
||||
def __enter__(self) -> Image: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(self, *args: Any) -> None: ...
|
||||
def close(self) -> None: ...
|
||||
def __eq__(self, other: object) -> bool: ...
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from _typeshed import Self
|
||||
from typing import Any
|
||||
|
||||
log: Any
|
||||
@@ -12,7 +13,7 @@ class TraceHeader:
|
||||
self, root: str | None = ..., parent: str | None = ..., sampled: bool | None = ..., data: dict[str, Any] | None = ...
|
||||
) -> None: ...
|
||||
@classmethod
|
||||
def from_header_str(cls, header): ...
|
||||
def from_header_str(cls: type[Self], header) -> Self: ...
|
||||
def to_header_str(self): ...
|
||||
@property
|
||||
def root(self): ...
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import threading
|
||||
from _typeshed import Self
|
||||
from types import TracebackType
|
||||
from typing import Iterator, Protocol
|
||||
from typing_extensions import Literal
|
||||
@@ -22,7 +23,7 @@ class Spinner(object):
|
||||
def start(self) -> None: ...
|
||||
def stop(self) -> None: ...
|
||||
def init_spin(self) -> None: ...
|
||||
def __enter__(self) -> Spinner: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(
|
||||
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
|
||||
) -> Literal[False]: ...
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from _typeshed import Self
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from typing import ClassVar
|
||||
|
||||
@@ -174,7 +175,7 @@ class EllipticCurvePublicNumbers(object):
|
||||
def y(self) -> int: ...
|
||||
def __init__(self, x: int, y: int, curve: EllipticCurve) -> None: ...
|
||||
@classmethod
|
||||
def from_encoded_point(cls, curve: EllipticCurve, data: bytes) -> EllipticCurvePublicNumbers: ...
|
||||
def from_encoded_point(cls: type[Self], curve: EllipticCurve, data: bytes) -> Self: ...
|
||||
def public_key(self, backend: EllipticCurveBackend | None = ...) -> EllipticCurvePublicKey: ...
|
||||
|
||||
class EllipticCurveSignatureAlgorithm(metaclass=ABCMeta):
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
from _typeshed import Self
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from enum import Enum
|
||||
from ipaddress import IPv4Address, IPv4Network, IPv6Address, IPv6Network
|
||||
@@ -325,10 +326,10 @@ class AuthorityKeyIdentifier(ExtensionType):
|
||||
) -> None: ...
|
||||
@classmethod
|
||||
def from_issuer_public_key(
|
||||
cls, public_key: RSAPublicKey | DSAPublicKey | EllipticCurvePublicKey | Ed25519PublicKey | Ed448PublicKey
|
||||
) -> AuthorityKeyIdentifier: ...
|
||||
cls: type[Self], public_key: RSAPublicKey | DSAPublicKey | EllipticCurvePublicKey | Ed25519PublicKey | Ed448PublicKey
|
||||
) -> Self: ...
|
||||
@classmethod
|
||||
def from_issuer_subject_key_identifier(cls, ski: SubjectKeyIdentifier) -> AuthorityKeyIdentifier: ...
|
||||
def from_issuer_subject_key_identifier(cls: type[Self], ski: SubjectKeyIdentifier) -> Self: ...
|
||||
|
||||
class SubjectKeyIdentifier(ExtensionType):
|
||||
@property
|
||||
@@ -336,8 +337,8 @@ class SubjectKeyIdentifier(ExtensionType):
|
||||
def __init__(self, digest: bytes) -> None: ...
|
||||
@classmethod
|
||||
def from_public_key(
|
||||
cls, public_key: RSAPublicKey | DSAPublicKey | EllipticCurvePublicKey | Ed25519PublicKey | Ed448PublicKey
|
||||
) -> SubjectKeyIdentifier: ...
|
||||
cls: type[Self], public_key: RSAPublicKey | DSAPublicKey | EllipticCurvePublicKey | Ed25519PublicKey | Ed448PublicKey
|
||||
) -> Self: ...
|
||||
|
||||
class AccessDescription:
|
||||
@property
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from _typeshed import Self
|
||||
from typing import Any
|
||||
|
||||
class Settings:
|
||||
def __new__(cls, *args, **kw) -> Settings: ...
|
||||
def __new__(cls: type[Self], *args, **kw) -> Self: ...
|
||||
def __init__(self, settings: Any | None = ...) -> None: ...
|
||||
@classmethod
|
||||
def get_key(cls, settings: Any | None = ...): ...
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import abc
|
||||
from _typeshed import Self
|
||||
from typing import Any
|
||||
|
||||
ConnectionError: Any
|
||||
@@ -37,7 +38,7 @@ class _InProcessGlobalCache(GlobalCache):
|
||||
class RedisCache(GlobalCache):
|
||||
transient_errors: Any
|
||||
@classmethod
|
||||
def from_environment(cls, strict_read: bool = ..., strict_write: bool = ...): ...
|
||||
def from_environment(cls: type[Self], strict_read: bool = ..., strict_write: bool = ...) -> Self: ...
|
||||
redis: Any
|
||||
strict_read: Any
|
||||
strict_write: Any
|
||||
@@ -59,7 +60,9 @@ class MemcacheCache(GlobalCache):
|
||||
def __eq__(self, other): ...
|
||||
transient_errors: Any
|
||||
@classmethod
|
||||
def from_environment(cls, max_pool_size: int = ..., strict_read: bool = ..., strict_write: bool = ...): ...
|
||||
def from_environment(
|
||||
cls: type[Self], max_pool_size: int = ..., strict_read: bool = ..., strict_write: bool = ...
|
||||
) -> Self: ...
|
||||
client: Any
|
||||
strict_read: Any
|
||||
strict_write: Any
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
from _typeshed import Self
|
||||
from collections.abc import Iterable, Sequence
|
||||
from typing import Callable, NoReturn
|
||||
from typing_extensions import Literal
|
||||
@@ -26,7 +27,7 @@ class _NotEqualMixin:
|
||||
DirectionT = Literal["asc", "desc"]
|
||||
|
||||
class IndexProperty(_NotEqualMixin):
|
||||
def __new__(cls, name: str, direction: DirectionT) -> IndexProperty: ...
|
||||
def __new__(cls: type[Self], name: str, direction: DirectionT) -> Self: ...
|
||||
@property
|
||||
def name(self) -> str: ...
|
||||
@property
|
||||
@@ -35,7 +36,7 @@ class IndexProperty(_NotEqualMixin):
|
||||
def __hash__(self) -> int: ...
|
||||
|
||||
class Index(_NotEqualMixin):
|
||||
def __new__(cls, kind: str, properties: list[IndexProperty], ancestor: bool) -> Index: ...
|
||||
def __new__(cls: type[Self], kind: str, properties: list[IndexProperty], ancestor: bool) -> Self: ...
|
||||
@property
|
||||
def kind(self) -> str: ...
|
||||
@property
|
||||
@@ -57,7 +58,8 @@ class IndexState(_NotEqualMixin):
|
||||
def __hash__(self) -> int: ...
|
||||
|
||||
class ModelAdapter:
|
||||
def __new__(cls, *args, **kwargs) -> ModelAdapter: ...
|
||||
# This actually returns NoReturn, but mypy can't handle that
|
||||
def __new__(cls: type[Self], *args, **kwargs) -> Self: ...
|
||||
|
||||
def make_connection(*args, **kwargs) -> NoReturn: ...
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from _typeshed import Self
|
||||
from collections.abc import Callable, Mapping, Sequence
|
||||
from typing import Any, Generic, TypeVar, overload
|
||||
from typing_extensions import Literal
|
||||
@@ -33,8 +34,13 @@ DEFAULT: Any
|
||||
|
||||
class _Call(tuple[Any, ...]):
|
||||
def __new__(
|
||||
cls, value: Any = ..., name: Any | None = ..., parent: Any | None = ..., two: bool = ..., from_kall: bool = ...
|
||||
) -> Any: ...
|
||||
cls: type[Self],
|
||||
value: Any = ...,
|
||||
name: Any | None = ...,
|
||||
parent: Any | None = ...,
|
||||
two: bool = ...,
|
||||
from_kall: bool = ...,
|
||||
) -> Self: ...
|
||||
name: Any
|
||||
parent: Any
|
||||
from_kall: Any
|
||||
@@ -60,7 +66,7 @@ class Base:
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
|
||||
|
||||
class NonCallableMock(Base, Any):
|
||||
def __new__(__cls, *args: Any, **kw: Any) -> NonCallableMock: ...
|
||||
def __new__(__cls: type[Self], *args: Any, **kw: Any) -> Self: ...
|
||||
def __init__(
|
||||
self,
|
||||
spec: list[str] | object | type[object] | None = ...,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from _typeshed import Self
|
||||
from typing import Any, Mapping
|
||||
|
||||
from .retry import Retry
|
||||
@@ -178,7 +179,7 @@ class UnixDomainSocketConnection(Connection):
|
||||
|
||||
class ConnectionPool:
|
||||
@classmethod
|
||||
def from_url(cls, url: str, *, db: int = ..., decode_components: bool = ..., **kwargs) -> ConnectionPool: ...
|
||||
def from_url(cls: type[Self], url: str, *, db: int = ..., decode_components: bool = ..., **kwargs) -> Self: ...
|
||||
connection_class: Any
|
||||
connection_kwargs: Any
|
||||
max_connections: Any
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import io
|
||||
from _typeshed import Self
|
||||
from http.client import HTTPMessage as _HttplibHTTPMessage, HTTPResponse as _HttplibHTTPResponse
|
||||
from typing import Any, Iterator, Mapping
|
||||
from typing_extensions import Literal
|
||||
@@ -83,7 +84,7 @@ class HTTPResponse(io.IOBase):
|
||||
def read(self, amt: int | None = ..., decode_content: bool | None = ..., cache_content: bool = ...) -> bytes: ...
|
||||
def stream(self, amt: int | None = ..., decode_content: bool | None = ...) -> Iterator[bytes]: ...
|
||||
@classmethod
|
||||
def from_httplib(cls, r: _HttplibHTTPResponse, **response_kw: Any) -> HTTPResponse: ...
|
||||
def from_httplib(cls: type[Self], r: _HttplibHTTPResponse, **response_kw: Any) -> Self: ...
|
||||
def getheaders(self) -> HTTPHeaderDict: ...
|
||||
def getheader(self, name, default=...) -> str | None: ...
|
||||
def info(self) -> HTTPHeaderDict: ...
|
||||
|
||||
Reference in New Issue
Block a user