mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
[3.14] gh-135646: Raise consistent NameError
exceptions in ForwardRef.evaluate()
(GH-135663) (#135673)
gh-135646: Raise consistent `NameError` exceptions in `ForwardRef.evaluate()` (GH-135663)
(cherry picked from commit 343719d98e
)
Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>
This commit is contained in:
parent
9ac369cb73
commit
d4daf4da7e
3 changed files with 8 additions and 2 deletions
|
@ -27,6 +27,9 @@ class Format(enum.IntEnum):
|
|||
|
||||
|
||||
_sentinel = object()
|
||||
# Following `NAME_ERROR_MSG` in `ceval_macros.h`:
|
||||
_NAME_ERROR_MSG = "name '{name:.200}' is not defined"
|
||||
|
||||
|
||||
# Slots shared by ForwardRef and _Stringifier. The __forward__ names must be
|
||||
# preserved for compatibility with the old typing.ForwardRef class. The remaining
|
||||
|
@ -184,7 +187,7 @@ class ForwardRef:
|
|||
elif is_forwardref_format:
|
||||
return self
|
||||
else:
|
||||
raise NameError(arg)
|
||||
raise NameError(_NAME_ERROR_MSG.format(name=arg), name=arg)
|
||||
else:
|
||||
code = self.__forward_code__
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue