Skip to content

Commit 04f0113

Browse files
authored
dataclasses: work around default factory issues (#5718)
1 parent c6b7835 commit 04f0113

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

stdlib/dataclasses.pyi

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import sys
22
from typing import Any, Callable, Dict, Generic, Iterable, List, Mapping, Optional, Tuple, Type, TypeVar, Union, overload
3+
from typing_extensions import Protocol
34

45
if sys.version_info >= (3, 9):
56
from types import GenericAlias
67

78
_T = TypeVar("_T")
9+
_T_co = TypeVar("_T_co", covariant=True)
810

911
class _MISSING_TYPE: ...
1012

@@ -63,11 +65,15 @@ else:
6365
*, init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., unsafe_hash: bool = ..., frozen: bool = ...
6466
) -> Callable[[Type[_T]], Type[_T]]: ...
6567

68+
# See https://github.com/python/mypy/issues/10750
69+
class _DefaultFactory(Protocol[_T_co]):
70+
def __call__(self) -> _T_co: ...
71+
6672
class Field(Generic[_T]):
6773
name: str
6874
type: Type[_T]
6975
default: _T
70-
default_factory: Callable[[], _T]
76+
default_factory: _DefaultFactory[_T]
7177
repr: bool
7278
hash: Optional[bool]
7379
init: bool

0 commit comments

Comments
 (0)