Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 24, 2025
Merged

Conversation

JelleZijlstra
Copy link
Member

python/cpython#133772 (TypedDict change)

python/cpython#133822 (NamedTuple change for 3.15)

@JelleZijlstra JelleZijlstra requested a review from AlexWaygood May 24, 2025 16:31
Comment on lines +4407 to +4419
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]

Copy link
Collaborator

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?

Copy link
Collaborator

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?

Copy link
Member Author

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 and textwrap.dedent.

@JelleZijlstra JelleZijlstra merged commit ec1876c into python:main May 24, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.