GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Positional arguments to TypedDict constructor · Issue #2161 · python/typing Open Labels topic: typing specFor improving the typing specFor improving the typing spec DescriptionThe spec says "The constructor takes only keyword arguments, corresponding to the items of the TypedDict." This derives from wording in PEP 589 "It can be used as a callable object with keyword arguments corresponding to the TypedDict items. Non-keyword arguments are not allowed." But at runtime, the TypedDict constructor also takes positional arguments. This works: from typing import TypedDict class TD1(TypedDict): a: int class TD2(TD1): b: str def f(x: TD2) -> TD1: return TD1(x) Pyright allows this program; mypy does not and reports The spec should say whether or not this should be allowed. (My opinion: it should be allowed, since it works at runtime and doesn't appear to break any type safety rule.) At runtime, even more is allowed; the TypedDict constructor actually allows whatever Activity
MetadataMetadataAssigneesLabelstopic: typing specFor improving the typing specFor improving the typing spec ProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |