Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 26, 2025

Pytest on RustPython failed when evaluating bool | Callable[...] because typing’s _CallableGenericAlias wasn’t accepted as unionable.

  • Unionability fix
    • Treat typing generic aliases (objects with __origin__/__args__ from the typing module) as valid union operands alongside built-in types and GenericAlias.
  • Regression coverage
    • Added snippet typing_callable_union.py to ensure bool | typing.Callable[[int], int] no longer raises.

Example:

from typing import Callable
TracebackFilter = bool | Callable[[int], int]  # now succeeds
Original prompt

This section details on the original issue you should resolve

<issue_title>TypeError: '|' not supported between instances of 'type' and '_CallableGenericAlias'</issue_title>
<issue_description>I'm trying to use pytest to have full test coverage in xonsh shell

rustpython -V
# Python 3.13.0alpha (heads/master:40acd5529
rustpython -m pip install pytest
cd /tmp
git clone https://github.com/xonsh/xonsh
cd xonsh
pytest
Traceback (most recent call last):
  File "/Users/pc/.local/bin/pytest", line 3, in <module>
    from pytest import console_main
  File "/Users/pc/.local/lib/rustpython3.13/site-packages/pytest/__init__.py", line 8, in <module>
    from _pytest._code import ExceptionInfo
  File "/Users/pc/.local/lib/rustpython3.13/site-packages/_pytest/_code/__init__.py", line 5, in <module>
    from .code import Code
  File "/Users/pc/.local/lib/rustpython3.13/site-packages/_pytest/_code/code.py", line 862, in <module>
    TracebackFilter: TypeAlias = bool | Callable[[ExceptionInfo[BaseException]], Traceback]
TypeError: '|' not supported between instances of 'type' and '_CallableGenericAlias'
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 26, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI changed the title [WIP] Fix TypeError in pytest compatibility with rustpython Handle unions with typing.Callable aliases without TypeError Dec 26, 2025
Copilot AI requested a review from youknowone December 26, 2025 08:17
@github-actions
Copy link
Contributor

Code has been automatically formatted

The code in this PR has been formatted using cargo fmt --all.
Please pull the latest changes before pushing again:

git pull origin copilot/fix-typeerror-in-pytest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: '|' not supported between instances of 'type' and '_CallableGenericAlias'

2 participants