Are type-checker directives in the body of a TypedDict
class disallowed?
#1914
-
I'd like to simplify some field declarations for use across multiple platforms/python versions etc. like you'd normally do in (non- import typing as t
import sys
class A(t.TypedDict):
if sys.version_info >= (3, 11):
a: int I understand the spec as saying that this is disallowed*:
I'm wondering if there's any particular reason for this restriction, or if this is just an oversight in the wording. Currently, the type-checkers behave inconsistently:
* However, field docstrings are currently allowed on from typing import TypedDict
class A(TypedDict):
a: int
"""An integer""" # No type-checker complains here |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
I think this should be allowed. Feel free to submit a change to the spec to make this explicit. This should also apply to NamedTuple bodies. |
Beta Was this translation helpful? Give feedback.
I think this should be allowed. Feel free to submit a change to the spec to make this explicit.
This should also apply to NamedTuple bodies.