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 subclasses of types.GenericAlias and types.UnionType as valid union operands, removing the prior typing-specific check.
  • Regression coverage
    • Added the bool | typing.Callable snippet to extra_tests/snippets/stdlib_typing.py to ensure the case 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

Warning

Rate limit exceeded

@youknowone has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 4 minutes and 46 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between c9bf8df and 3b4e565.

⛔ Files ignored due to path filters (1)
  • Lib/test/test_types.py is excluded by !Lib/**
📒 Files selected for processing (2)
  • crates/vm/src/builtins/union.rs
  • extra_tests/snippets/stdlib_typing.py

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch copilot/fix-typeerror-in-pytest

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copilot AI and others added 11 commits December 26, 2025 07:57
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
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

Copy link
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ensure test_types and test_typing working

Comment on lines 179 to 185
let Some(_) = module
.as_ref()
.and_then(|m| m.downcast_ref::<PyStr>())
.filter(|m| m.as_str() == TYPING_MODULE)
else {
return false;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is wrong approach

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified unionability to allow subclasses of types.GenericAlias/types.UnionType instead of the prior typing-specific check (3b4e565).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test need to be placed in extra_tests/snippets/stdlib_typing.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the Callable union snippet into extra_tests/snippets/stdlib_typing.py and dropped the standalone file (3b4e565).

Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 26, 2025

ensure test_types and test_typing working

Ran targeted suites after the fixes: test_typing and test_types now pass (3b4e565).

Copilot AI changed the title Handle unions with typing.Callable aliases without TypeError Handle unions with GenericAlias subclasses without TypeError Dec 26, 2025
Copilot AI requested a review from youknowone December 26, 2025 11:54
@youknowone youknowone marked this pull request as ready for review December 26, 2025 12:27
@youknowone
Copy link
Member

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 26, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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