Make more miscellaneous fields read-only, annotate _json.make_encoder (#7439)

This commit is contained in:
Alex Waygood
2022-03-06 23:41:49 +00:00
committed by GitHub
parent 6cdecae6f9
commit bc72b25a2a
7 changed files with 63 additions and 31 deletions

View File

@@ -3,14 +3,22 @@ from typing_extensions import final
@final
class make_encoder:
sort_keys: Any
skipkeys: Any
key_separator: Any
indent: Any
markers: Any
default: Any
encoder: Any
item_separator: Any
@property
def sort_keys(self) -> bool: ...
@property
def skipkeys(self) -> bool: ...
@property
def key_separator(self) -> str: ...
@property
def indent(self) -> int | None: ...
@property
def markers(self) -> dict[int, Any] | None: ...
@property
def default(self) -> Callable[[Any], Any]: ...
@property
def encoder(self) -> Callable[[str], str]: ...
@property
def item_separator(self) -> str: ...
def __init__(
self,
markers: dict[int, Any] | None,

View File

@@ -527,9 +527,12 @@ else:
# ----- Classes -----
class socket:
family: int
type: int
proto: int
@property
def family(self) -> int: ...
@property
def type(self) -> int: ...
@property
def proto(self) -> int: ...
@property
def timeout(self) -> float | None: ...
def __init__(self, family: int = ..., type: int = ..., proto: int = ..., fileno: _FD | None = ...) -> None: ...

View File

@@ -13,8 +13,10 @@ _T = TypeVar("_T", int, float, str)
typecodes: str
class array(MutableSequence[_T], Generic[_T]):
typecode: _TypeCode
itemsize: int
@property
def typecode(self) -> _TypeCode: ...
@property
def itemsize(self) -> int: ...
@overload
def __init__(self: array[int], __typecode: _IntTypeCode, __initializer: bytes | Iterable[_T] = ...) -> None: ...
@overload

View File

@@ -2,7 +2,7 @@ import sys
from _typeshed import Self
from concurrent.futures._base import Error, Future as _ConcurrentFuture
from typing import Any, Awaitable, Callable, Generator, Iterable, TypeVar
from typing_extensions import TypeGuard
from typing_extensions import Literal, TypeGuard
from .events import AbstractEventLoop
@@ -42,9 +42,13 @@ if sys.version_info < (3, 7):
class Future(Awaitable[_T], Iterable[_T]):
_state: str
_exception: BaseException
@property
def _exception(self) -> BaseException: ...
_blocking: bool
_log_traceback: bool
@property
def _log_traceback(self) -> bool: ...
@_log_traceback.setter
def _log_traceback(self, val: Literal[False]) -> None: ...
_asyncio_future_blocking: bool # is a part of duck-typing contract for `Future`
def __init__(self, *, loop: AbstractEventLoop | None = ...) -> None: ...
def __del__(self) -> None: ...

View File

@@ -99,9 +99,12 @@ def total_ordering(cls: type[_T]) -> type[_T]: ...
def cmp_to_key(mycmp: Callable[[_T, _T], int]) -> Callable[[_T], SupportsAllComparisons]: ...
class partial(Generic[_T]):
func: Callable[..., _T]
args: tuple[Any, ...]
keywords: dict[str, Any]
@property
def func(self) -> Callable[..., _T]: ...
@property
def args(self) -> tuple[Any, ...]: ...
@property
def keywords(self) -> dict[str, Any]: ...
def __new__(cls: type[Self], __func: Callable[..., _T], *args: Any, **kwargs: Any) -> Self: ...
def __call__(__self, *args: Any, **kwargs: Any) -> _T: ...
if sys.version_info >= (3, 9):

View File

@@ -387,8 +387,10 @@ class DirEntry(Generic[AnyStr]):
# This is what the scandir iterator yields
# The constructor is hidden
name: AnyStr
path: AnyStr
@property
def name(self) -> AnyStr: ...
@property
def path(self) -> AnyStr: ...
def inode(self) -> int: ...
def is_dir(self, *, follow_symlinks: bool = ...) -> bool: ...
def is_file(self, *, follow_symlinks: bool = ...) -> bool: ...

View File

@@ -1049,15 +1049,21 @@ class ByteString(Sequence[int], metaclass=ABCMeta): ...
@_final
class Match(Generic[AnyStr]):
pos: int
endpos: int
lastindex: int | None
lastgroup: str | None
string: AnyStr
@property
def pos(self) -> int: ...
@property
def endpos(self) -> int: ...
@property
def lastindex(self) -> int | None: ...
@property
def lastgroup(self) -> str | None: ...
@property
def string(self) -> AnyStr: ...
# The regular expression object whose match() or search() method produced
# this match instance.
re: Pattern[AnyStr]
@property
def re(self) -> Pattern[AnyStr]: ...
def expand(self, template: AnyStr) -> AnyStr: ...
# group() returns "AnyStr" or "AnyStr | None", depending on the pattern.
@overload
@@ -1095,10 +1101,14 @@ class Match(Generic[AnyStr]):
@_final
class Pattern(Generic[AnyStr]):
flags: int
groupindex: Mapping[str, int]
groups: int
pattern: AnyStr
@property
def flags(self) -> int: ...
@property
def groupindex(self) -> Mapping[str, int]: ...
@property
def groups(self) -> int: ...
@property
def pattern(self) -> AnyStr: ...
def search(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> Match[AnyStr] | None: ...
def match(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> Match[AnyStr] | None: ...
def fullmatch(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> Match[AnyStr] | None: ...