Skip to content

Failure to resolve signature when TypeAliasForwardRef appears in union expressions #14004

@taminomara

Description

@taminomara

Describe the bug

When TypeAliasForwardRef appears in expressions like Alias | None, signature evaluation fails with TypeError: unsupported operand type(s) for |: 'type' and 'TypeAliasForwardRef'.

Adding __or__ and __ror__ to TypeAliasForwardRef would fix this, I'll send a patch later today if it's ok (I've heard that you're working on rewrite around autodoc, but this is a small change.)

How to Reproduce

Example: when autodoc renders function test from this code:

from __future__ import annotations
from typing import *

Alias: TypeAlias = int

def test() -> Alias | None: ...

if Alias appears in autodoc_type_aliases, the resulting signature will not evaluate, leading to further errors down the line.

Environment Information

Platform:              linux; (Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.39)
Python version:        3.13.8 (main, Oct 12 2025, 16:57:39) [GCC 13.3.0])
Python implementation: CPython
Sphinx version:        8.2.3
Docutils version:      0.21.2
Jinja2 version:        3.1.6
Pygments version:      2.19.2

Sphinx extensions

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions