-
-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support my PEP 649 branch #412
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -942,7 +942,13 @@ def __new__(cls, name, bases, ns, *, total=True, closed=False): | |
tp_dict.__orig_bases__ = bases | ||
|
||
annotations = {} | ||
own_annotations = ns.get('__annotations__', {}) | ||
if "__annotations__" in ns: | ||
own_annotations = ns["__annotations__"] | ||
elif "__annotate__" in ns: | ||
# TODO: Use inspect.VALUE here, and make the annotations lazily evaluated | ||
own_annotations = ns["__annotate__"](1) | ||
else: | ||
own_annotations = {} | ||
Comment on lines
+945
to
+951
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mentioned in python/cpython#119361 (comment) that you'd be adding a helper function for this kind of thing at some point -- would it be worth waiting for that, since the first 3.14 alpha is some way off? I can also see the advantages of getting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do expect we'll need more changes later, but it's helpful to get this merged so I can test the rest of the ecosystem too. |
||
msg = "TypedDict('Name', {f0: t0, f1: t1, ...}); each t must be a type" | ||
if _TAKES_MODULE: | ||
own_annotations = { | ||
|
@@ -3104,7 +3110,13 @@ def __new__(cls, typename, bases, ns): | |
raise TypeError( | ||
'can only inherit from a NamedTuple type and Generic') | ||
bases = tuple(tuple if base is _NamedTuple else base for base in bases) | ||
types = ns.get('__annotations__', {}) | ||
if "__annotations__" in ns: | ||
types = ns["__annotations__"] | ||
elif "__annotate__" in ns: | ||
# TODO: Use inspect.VALUE here, and make the annotations lazily evaluated | ||
types = ns["__annotate__"](1) | ||
else: | ||
types = {} | ||
default_names = [] | ||
for field_name in types: | ||
if field_name in ns: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add an
assert system.version >= (3, 14)
inside theexcept
block?