Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyright incompatible with constructing nested exceptiongroups with exceptiongroup backport #6795

Closed
jakkdl opened this issue Dec 22, 2023 · 1 comment
Labels
as designed Not a bug, working as intended bug Something isn't working

Comments

@jakkdl
Copy link

jakkdl commented Dec 22, 2023

Describe the bug
I'm not 100% sure if this is an error in the signature for the backport, or in pyright. But strict mypy handles it without problem both on <3.11 and >=3.11. The code works without problem if pyright is targeting version==3.11.

I encountered the error in the following PR: python-trio/trio#2898
https://github.com/python-trio/trio/actions/runs/7300704573/job/19895902558?pr=2898#step:5:1647

Code or Screenshots
foo.py

import sys
if sys.version_info < (3, 11):
    from exceptiongroup import ExceptionGroup

exc: ExceptionGroup[ExceptionGroup[ValueError]] = ExceptionGroup(
    "", (ExceptionGroup("", (ValueError(),)),)
)

pyproject.toml

[tool.pyright]
pythonVersion = "3.10"
typeCheckingMode = "strict"
$ pyright foo.py                            
/tmp/pyright_exceptiongroup/foo.py
  /tmp/pyright_exceptiongroup/foo.py:6:9 - error: Argument type is partially unknown
    Argument corresponds to parameter "args" in function "__init__"
    Argument type is "tuple[ExceptionGroup[Unknown]]" (reportUnknownArgumentType)
1 error, 0 warnings, 0 informations 
$ pip list
Package           Version
----------------- -------
exceptiongroup    1.2.0
pyright           1.1.342
[...]

The signature in the backport can be seen at https://github.com/agronholm/exceptiongroup/blob/main/src/exceptiongroup/_exceptions.py and as far as I can tell it doesn't differ from the one in typeshed https://github.com/python/typeshed/blob/main/stdlib/builtins.pyi#L2130

@erictraut
Copy link
Collaborator

This is a due to a bug in the exceptiongroups library. The exceptiongroup/_exceptions.py module contains the following import statement:

if TYPE_CHECKING:
    from typing import Self

But the Self symbol isn't exported from the typing module for Python versions older than 3.11. The symbol should be imported from typing_extensions instead.

This doesn't affect mypy because mypy does not honor the return type of __new__. If and when mypy maintainers implement support for __new__ return type annotations, this same bug will affect mypy.

@erictraut erictraut added the as designed Not a bug, working as intended label Dec 22, 2023
@erictraut erictraut closed this as not planned Won't fix, can't repro, duplicate, stale Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
as designed Not a bug, working as intended bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants