how to correctly create a dict subclass with typing #1033
-
we have a lot of classes that subclass I'm not able to create a custom subclass of Currently, trying to figure out the What's the correct return type for example below # Module "builtins" has no attribute "dict_values"
from builtins import dict_values # type: ignore
import time
from typing import Any
from typing import cast
from typing import Dict, List
from typing import Tuple
from typing import TypeVar
from typing import ValuesView
_KT = TypeVar("_KT", |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
Yeah this was broken in 3.10, see here: https://bugs.python.org/issue46399 We're trying to figure out some solutions! |
Beta Was this translation helpful? Give feedback.
-
i know this is a different question but similar area, what's the correct typing for setdefault()? if I have a dict[str, str], how is the None value implied by setdefault accommodated? import typing
from typing import Dict
x: Dict[str, str] = {"a": "b"}
# we would think typing would raise an error for this
q = x.setdefault("c")
if typing.TYPE_CHECKING:
# Revealed type is "builtins.str*"
reveal_type(q)
# which is wrong. it's None
assert q is not None |
Beta Was this translation helpful? Give feedback.
Yeah this was broken in 3.10, see here: https://bugs.python.org/issue46399
We're trying to figure out some solutions!