Skip to content

Handle unions with GenericAlias subclasses without TypeError - #6540

Merged
youknowone merged 16 commits into
mainfrom
copilot/fix-typeerror-in-pytest
Dec 26, 2025
Merged

youknowone merged 16 commits into
mainfrom
copilot/fix-typeerror-in-pytest

Conversation

Copilot AI commented Dec 26, 2025 •

Copy link
Copy Markdown
Contributor
  • Treat subclasses of GenericAlias/UnionType as unionable; move Callable union snippet into stdlib_typing
  • Make union dedup robust to comparison errors
  • Enable union parameter substitution test
  • Run test_typing, test_types, and clippy on core crates
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

coderabbitai Bot commented Dec 26, 2025 •

Copy link
Copy Markdown
Contributor

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.

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.


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
Copy Markdown
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

@youknowone youknowone left a comment

Copy link
Copy Markdown
Member

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 thread crates/vm/src/builtins/union.rs Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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).

Copilot AI commented Dec 26, 2025

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
Member

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Dec 26, 2025

Copy link
Copy Markdown
Contributor
✅ 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.

@youknowone

Copy link
Copy Markdown
Member

@copilot fix clippy

Copilot AI commented Dec 26, 2025

Copy link
Copy Markdown
Contributor Author

@copilot fix clippy

Clippy is clean now for the core crates; see 1d2b0db.

Copilot AI and others added 9 commits December 26, 2025 23:42
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 and others added 7 commits December 26, 2025 23:42
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>
@youknowone
youknowone force-pushed the copilot/fix-typeerror-in-pytest branch from 1d2b0db to c2c29c6 Compare December 26, 2025 15:12
@youknowone
youknowone merged commit a7d7f81 into main Dec 26, 2025
13 checks passed
@youknowone
youknowone deleted the copilot/fix-typeerror-in-pytest branch December 26, 2025 16:13
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