Uh oh!
There was an error while loading. Please reload this page.
gh-82129: Provide __annotate__ method for dataclasses from make_dataclass - #122262
gh-82129: Provide __annotate__ method for dataclasses from make_dataclass#122262sobolevn wants to merge 10 commits into
__annotate__ method for dataclasses from make_dataclass#122262Conversation
sobolevn
commented
Jul 25, 2024
Test failure: is expected, I just don't want to touch tests at this point. |
__annotate__ method for dataclasses from make_dataclass__annotate__ method for dataclasses from make_dataclassDavidCEllis
commented
Jul 25, 2024
I mentioned it on the issue but with this change If you want to avoid the typing import this way you need to put some placeholder for This doesn't happen on the 3.13 version proposed because dataclasses doesn't evaluate the strings so the import doesn't get called by dataclasses when it looks at the annotations. |
Uh oh!
There was an error while loading. Please reload this page.
JelleZijlstra
commented
Jul 25, 2024
You might be able to get around @DavidCEllis's point by adding some internal-only flag to tell |
Perhaps you can take advantage of If it's called with |
sobolevn
commented
Jul 25, 2024
Yes, this is my go-to idea right now :) |
sobolevn
commented
Sep 18, 2024
This PR still does not account for the problem mentioned by @DavidCEllis I will try to work around this problem. |
sobolevn
commented
Sep 18, 2024
But, since cc @JelleZijlstra about my question in #122285 |
Uh oh!
There was an error while loading. Please reload this page.
Now Thanks everyone for your help and ideas! 🤝 |
| def annotate_method(format): | ||
| typing = sys.modules.get("typing") | ||
| if typing is None and format == annotationlib.Format.FORWARDREF: |
There was a problem hiding this comment.
We could also avoid importing typing for the SOURCE format here I think; is that worth it?
There was a problem hiding this comment.
I am not sure we can. I need _convert_to_source, there can be complex annotations that should be formatted properly. I will open a new issue about converting annotations to string with public API though. Right now I don't see a clear way.
Uh oh!
There was an error while loading. Please reload this page.
…wt3u.rst Co-authored-by: Carl Meyer <carl@oddbird.net>
Uh oh!
There was an error while loading. Please reload this page.
sobolevn
commented
Oct 15, 2024
I realized there's now new way to convert annotations to source. Fixing! |
sobolevn
commented
Oct 15, 2024
Blocked by #125507 |
This is my plan for python3.14+
While #122232 can be backported to older versions and solve their problems, this one is actually a correct way to solve this problem for the future.
This is a WIP, because I think that we should first decide on #122232