[New-bugs-announce] [issue41987] singledispatchmethod raises an error when relying on a forward declaration
Glyph Lefkowitz
report at bugs.python.org
Fri Oct 9 16:11:43 EDT 2020
New submission from Glyph Lefkowitz <glyph at twistedmatrix.com>:
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, arg: Comparable):
return "somewhat similar"
print(Comparable().compare(Comparable()))
Produces this result:
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/typing.py", line 518, in _evaluate
eval(self.__forward_code__, globalns, localns),
File "<string>", line 1, in <module>
NameError: name 'Comparable' is not defined
It seems like perhaps singledispatchmethod should defer its type evaluation to its first invocation?
----------
components: Library (Lib)
messages: 378346
nosy: glyph
priority: normal
severity: normal
stage: needs patch
status: open
title: singledispatchmethod raises an error when relying on a forward declaration
type: behavior
versions: Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41987>
_______________________________________
More information about the New-bugs-announce
mailing list