Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork117
More fixes for 3.14 and 3.15#602
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
def _make_td(future, class_name, annos, base, extra_names=None): | ||
lines = [] | ||
if future: | ||
lines.append('from __future__ import annotations') | ||
lines.append('from typing import TypedDict') | ||
lines.append(f'class {class_name}({base}):') | ||
for name, anno in annos.items(): | ||
lines.append(f' {name}: {anno}') | ||
code = '\n'.join(lines) | ||
ns = {**extra_names} if extra_names else {} | ||
exec(code, ns) | ||
return ns[class_name] | ||
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.
This is all very magical. Wouldn't it make more sense to just hard-code these four fairly short code samples?
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.
Ah, it's eight. So maybe use a template at least?
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.
I feel that would be more complicated; it would require conditionals on half the lines of the template andtextwrap.dedent
.
ec1876c
intopython:mainUh oh!
There was an error while loading.Please reload this page.
python/cpython#133772 (TypedDict change)
python/cpython#133822 (NamedTuple change for 3.15)