GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||
GeezerVison is showing github.com — bpo-41341: Recursive evaluation of ForwardRef in get_type_hints by wyfo · Pull Request #21553 · python/cpython Conversation
|
| {'a': tuple[T]}) | ||
|
|
||
| def test_double_forward(self): | ||
| def foo(a: 'List[\'int\']'): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I was about to approve this PR when I realized that we should make this work with list -- I tried and it doesn't currently.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
You're right concerning the fact that it doesn't work with list, but I've found that it's not related to this PR; actually, I think there is a significant defect in current PEP 585 implementation. In fact:
from dataclasses import dataclass, field from typing import get_type_hints, List, ForwardRef @dataclass class Node: children: list["Node"] = field(default_factory=list) children2: List["Node"] = field(default_factory=list) assert get_type_hints(Node) == {"children": list["Node"], "children2": List[Node]} assert List["Node"].__args__ == (ForwardRef("Node"),) assert list["Node"].__args__ == ("Node",) # No ForwardRef here, so no evaluation by get_type_hints
I will open an issue on bugs.python.org to discuss about this, because I think this PR is not the best place to do it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Heh, you're right, thanks for the analysis. We probably will not ever support this: importing ForwardRef from the built-in generic alias code would be problematic, and once from __future__ import annotations is always on there's no need to quote the argument anyway. Sorry for the hiccup. I will now approve your PR.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I had my own implementations, but I think I am going to rebase because it was kind of a workaround. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@gvanrossum: Please replace |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@ambv @pablogsal can I please have a decision on whether to backport this to 3.9? See my previous comment. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I think it makes sense, but being this |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @wyfo for the PR, and @gvanrossum for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…onGH-21553) The issue raised by recursive evaluation is infinite recursion with recursive types. In that case, only the first recursive ForwardRef is evaluated. (cherry picked from commit 653f420) Co-authored-by: wyfo <[email protected]>
|
GH-21629 is a backport of this pull request to the 3.9 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…1553) The issue raised by recursive evaluation is infinite recursion with recursive types. In that case, only the first recursive ForwardRef is evaluated. (cherry picked from commit 653f420) Co-authored-by: wyfo <[email protected]>
…on#21553) The issue raised by recursive evaluation is infinite recursion with recursive types. In that case, only the first recursive ForwardRef is evaluated.
…on#21553) The issue raised by recursive evaluation is infinite recursion with recursive types. In that case, only the first recursive ForwardRef is evaluated.
…on#21553) The issue raised by recursive evaluation is infinite recursion with recursive types. In that case, only the first recursive ForwardRef is evaluated.
…f or str Related: python/cpython#21553 (comment) Signed-off-by: John Andersen <[email protected]>
…f or str Related: python/cpython#21553 (comment) Signed-off-by: John Andersen <[email protected]>
…f or str Related: python/cpython#21553 (comment) Signed-off-by: John Andersen <[email protected]>
…f or str Related: python/cpython#21553 (comment) Signed-off-by: John Andersen <[email protected]>
…f or str Related: python/cpython#21553 (comment) Signed-off-by: John Andersen <[email protected]>
recursive_guard argument was added in python/cpython#21553
…f or str Related: python/cpython#21553 (comment) Signed-off-by: John Andersen <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.