Skip to content

decoratorx requires from __future__ import annotations although it shouldn't in Python 3.14 #177

@bersbersbers

Description

@bersbersbers

This file is valid in Python 3.14, meaning, python bug.py does not error:

bug.py:

def foo(path: Path): ...

(In Python 3.13, it requires from __future__ import annotations.)

Now, adding a simple decoratorx raises the following error:

bug.py:

from decorator import decoratorx

@decoratorx
def identity(func, *args, **kwargs):
    return func(*args, **kwargs)

@identity
def foo(path: Path): ...

Potential workarounds include:

  • Path -> "Path" (but ruff undoes that)
  • add from pathlib import Path (but ruff wants to move that into a type-checking block)
  • add from __future__ import annotations

All of those work, but none of those should be necessary.

Similar issue with a proposed fix: pytest-dev/pluggy#629

(.venv) C:\Git\project>python bug.py
Traceback (most recent call last):
  File "C:\Users\bers\AppData\Roaming\uv\python\cpython-3.14.0-windows-x86_64-none\Lib\inspect.py", line 1261, in getfullargspec
    sig = _signature_from_callable(func,
                                   follow_wrapper_chains=False,
                                   skip_bound_arg=False,
                                   sigcls=Signature,
                                   eval_str=False)
  File "C:\Users\bers\AppData\Roaming\uv\python\cpython-3.14.0-windows-x86_64-none\Lib\inspect.py", line 2502, in _signature_from_callable       
    return _signature_from_function(sigcls, obj,
                                    skip_bound_arg=skip_bound_arg,
                                    globals=globals, locals=locals, eval_str=eval_str,
                                    annotation_format=annotation_format)
  File "C:\Users\bers\AppData\Roaming\uv\python\cpython-3.14.0-windows-x86_64-none\Lib\inspect.py", line 2325, in _signature_from_function       
    annotations = get_annotations(func, globals=globals, locals=locals, eval_str=eval_str,
                                  format=annotation_format)
  File "C:\Users\bers\AppData\Roaming\uv\python\cpython-3.14.0-windows-x86_64-none\Lib\annotationlib.py", line 890, in get_annotations
    ann = _get_dunder_annotations(obj)
  File "C:\Users\bers\AppData\Roaming\uv\python\cpython-3.14.0-windows-x86_64-none\Lib\annotationlib.py", line 1059, in _get_dunder_annotations  
    ann = getattr(obj, "__annotations__", None)
  File "C:\Git\project\bug.py", line 10, in __annotate__
    def foo(path: Path): ...
                  ^^^^
NameError: name 'Path' is not defined

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Git\project\bug.py", line 9, in <module>
    @identity
     ^^^^^^^^
  File "C:\Git\project\.venv\Lib\site-packages\decorator.py", line 277, in dec
    return FunctionMaker.create(
           ~~~~~~~~~~~~~~~~~~~~^
        func,
        ^^^^^
        "return _call_(_func_, %(shortsignature)s)",
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        dict(_call_=caller, _func_=func),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        __wrapped__=func, __qualname__=func.__qualname__)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Git\project\.venv\Lib\site-packages\decorator.py", line 189, in create
    self = cls(func, name, signature, defaults, doc, module)
  File "C:\Git\project\.venv\Lib\site-packages\decorator.py", line 76, in __init__
    argspec = getfullargspec(func)
  File "C:\Users\bers\AppData\Roaming\uv\python\cpython-3.14.0-windows-x86_64-none\Lib\inspect.py", line 1271, in getfullargspec
    raise TypeError('unsupported callable') from ex
TypeError: unsupported callable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions