| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| 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.
This is all very magical. Wouldn't it make more sense to just hard-code these four fairly short code samples?
Sorry, something went wrong.
There was a problem hiding this comment.
Ah, it's eight. So maybe use a template at least?
Sorry, something went wrong.
There was a problem hiding this comment.
I feel that would be more complicated; it would require conditionals on half the lines of the template and textwrap.dedent.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
python/cpython#133772 (TypedDict change)
python/cpython#133822 (NamedTuple change for 3.15)