dataclasses: work around default factory issues (#5718)

This commit is contained in:
Shantanu
2021-06-30 23:07:00 -07:00
committed by GitHub
parent c6b78354e6
commit 04f0113d16

View File

@@ -1,10 +1,12 @@
import sys
from typing import Any, Callable, Dict, Generic, Iterable, List, Mapping, Optional, Tuple, Type, TypeVar, Union, overload
from typing_extensions import Protocol
if sys.version_info >= (3, 9):
from types import GenericAlias
_T = TypeVar("_T")
_T_co = TypeVar("_T_co", covariant=True)
class _MISSING_TYPE: ...
@@ -63,11 +65,15 @@ else:
*, init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., unsafe_hash: bool = ..., frozen: bool = ...
) -> Callable[[Type[_T]], Type[_T]]: ...
# See https://github.com/python/mypy/issues/10750
class _DefaultFactory(Protocol[_T_co]):
def __call__(self) -> _T_co: ...
class Field(Generic[_T]):
name: str
type: Type[_T]
default: _T
default_factory: Callable[[], _T]
default_factory: _DefaultFactory[_T]
repr: bool
hash: Optional[bool]
init: bool