[issue41987] singledispatchmethod raises an error when relying on a forward declaration

2022-01-11 Thread Alex Waygood
Change by Alex Waygood : -- nosy: +AlexWaygood, lukasz.langa ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue41987] singledispatchmethod raises an error when relying on a forward declaration

2022-01-10 Thread Guido van Rossum
Guido van Rossum added the comment: Thanks for the bisection. It's not surprising that that's the culprit, and in other situations that's the right thing to do. I'm not sure how to address this without breaking other stuff -- maybe leave the ForwardRef if evaluating it doesn't work? But

[issue41987] singledispatchmethod raises an error when relying on a forward declaration

2022-01-03 Thread Jörn Heissler
Jörn Heissler added the comment: Hello! git-bisect points at https://bugs.python.org/issue41341 https://github.com/python/cpython/pull/21553 It breaks both the examples from https://bugs.python.org/issue41987#msg379896 and https://bugs.python.org/issue41987#msg380803 -- nosy:

[issue41987] singledispatchmethod raises an error when relying on a forward declaration

2020-11-12 Thread Guido van Rossum
Guido van Rossum added the comment: > Does anyone know why the treatment of unresolved references was changed in > 3.9? Probably to prepare for 3.10, where `from _future__ import annotations` is the default. > Also, I'm a bit puzzled about something from the previously mentioned Integer >

[issue41987] singledispatchmethod raises an error when relying on a forward declaration

2020-11-12 Thread Ryan Sobol
Ryan Sobol added the comment: Also, I'm a bit puzzled about something from the previously mentioned Integer class and its use of __future__.annotations. Why is it possible to declare an Integer return type for the add() method, but only possible to declare an "Integer" forward reference for

[issue41987] singledispatchmethod raises an error when relying on a forward declaration

2020-11-12 Thread Ryan Sobol
Ryan Sobol added the comment: Does anyone know why the treatment of unresolved references was changed in 3.9? -- ___ Python tracker ___

[issue41987] singledispatchmethod raises an error when relying on a forward declaration

2020-11-12 Thread Guido van Rossum
Guido van Rossum added the comment: So the biggest difference I see is that ForwardRef._evaluate() has grown a recursive_guard argument in 3.9. This makes me think that in 3.8, only one level of evaluation was happening, and in 3.8, we keep evaluating until we don't see a string or

[issue41987] singledispatchmethod raises an error when relying on a forward declaration

2020-11-11 Thread Guido van Rossum
Guido van Rossum added the comment: FWIW here's a minimal demo: from __future__ import annotations from typing import get_type_hints class C: def func(self, a: "C"): pass print(get_type_hints(func)) In 3.8 this prints {'a': ForwardRef('C')} while in 3.9 it raises

[issue41987] singledispatchmethod raises an error when relying on a forward declaration

2020-11-11 Thread Guido van Rossum
Guido van Rossum added the comment: Keep this issue. -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue41987] singledispatchmethod raises an error when relying on a forward declaration

2020-11-11 Thread mental
mental added the comment: Interesting! thanks for the hint guido I'll try to investigate further. This sounds like a regression (to me at least), in that case should a separate issue & patch PR be opened on the bpo or should this issue be used instead? --

[issue41987] singledispatchmethod raises an error when relying on a forward declaration

2020-11-11 Thread Guido van Rossum
Guido van Rossum added the comment: I spent some time debugging this looking for the root cause. I think it looks like the recursion check in ForwardRef._evaluate() fails to trigger. At some point recursive_guard is a frozen set containing "'Integer'" (i.e. a string whose first and last

[issue41987] singledispatchmethod raises an error when relying on a forward declaration

2020-11-09 Thread mental
Change by mental : -- keywords: +patch nosy: +mental nosy_count: 5.0 -> 6.0 pull_requests: +22113 stage: needs patch -> patch review pull_request: https://github.com/python/cpython/pull/23216 ___ Python tracker

[issue41987] singledispatchmethod raises an error when relying on a forward declaration

2020-10-29 Thread Guido van Rossum
Guido van Rossum added the comment: I'm not an expert on singledispatch. It seems the get_type_hints() call is present in 3.8 as well. Could you investigate and find a root cause? Then maybe we can fix it. (If you come up with a PR that would be very much appreciated.) -- versions:

[issue41987] singledispatchmethod raises an error when relying on a forward declaration

2020-10-29 Thread Ryan Sobol
Ryan Sobol added the comment: It's worth pointing out that a similar error is produced for a forward-referenced return type of a registered method, but only for python3.9. For example: from __future__ import annotations from functools import singledispatchmethod class Integer: def

[issue41987] singledispatchmethod raises an error when relying on a forward declaration

2020-10-09 Thread Glyph Lefkowitz
Glyph Lefkowitz added the comment: The behavior is the same with a traditional quoted forward declaration, so it’s not specific to the __future__ import; I just phrased the example that way to show how it’s going to look in the future and to illustrate how it might crop up in a way which is

[issue41987] singledispatchmethod raises an error when relying on a forward declaration

2020-10-09 Thread Guido van Rossum
Guido van Rossum added the comment: This behavior (only relevant with `from __future__ import annotations`) has been around since @singledispatchmethod was introduced in 3.8, so I agree we should treat it as a feature request. In the meantime, maybe a workaround is to move the register call

[issue41987] singledispatchmethod raises an error when relying on a forward declaration

2020-10-09 Thread Batuhan Taskaya
Batuhan Taskaya added the comment: AFAIK the normal way of registering types (dispatcher.register()) also requires that registered type be defined at the execution type. I guess, if we are going to support such a thing, we might end up with supporting passing strings into the .register() as

[issue41987] singledispatchmethod raises an error when relying on a forward declaration

2020-10-09 Thread Batuhan Taskaya
Change by Batuhan Taskaya : -- nosy: +BTaskaya ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue41987] singledispatchmethod raises an error when relying on a forward declaration

2020-10-09 Thread Glyph Lefkowitz
New submission from Glyph Lefkowitz : This example: from __future__ import annotations from functools import singledispatchmethod class Comparable: @singledispatchmethod def compare(self, arg: object): raise NotImplementedError("what") @compare.register def _(self,