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

Generic class using ParamSpec raises TypeError in Python < 3.10, with User Uncaught Exceptions + justMyCode: false #1340

Open
ringohoffman opened this issue Jul 29, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@ringohoffman
Copy link

ringohoffman commented Jul 29, 2023

Environment data

  • debugpy version: 1.6.7
  • OS and version: M1 Pro, macOS 13.5 (22G74)
  • Python version (& distribution if applicable, e.g. Anaconda): conda for M1/M2, Python 3.8.17
  • Using VS Code or Visual Studio: VS Code Version: 1.80.2 Commit: 2ccd690cbff1569e4a83d7c43d45101f817401dc

I didn't have this problem until today when I switched to conda for M1/M2 (from the Intel based one).

from typing import Generic

from typing_extensions import ParamSpec

P = ParamSpec("P")


class A(Generic[P]):
    ...

The above code executes fine:

$ python --version
Python 3.8.17
$ python a.py

Actual behavior

But when when both:

  1. justMyCode: false
  2. Breakpoints > User Uncaught Exceptions is checked
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "subProcess": true,
            "justMyCode": false
        },
    ]
}

I get this stack trace:

Exception has occurred: TypeError       (note: full exception trace is shown but execution is paused at: <module>)
Parameters to Generic[...] must all be type variables
  File "/Users/ringo/anaconda3/envs/glass38/lib/python3.8/typing.py", line 890, in __class_getitem__
    raise TypeError(
  File "/Users/ringo/anaconda3/envs/glass38/lib/python3.8/typing.py", line 261, in inner
    return func(*args, **kwds)
  File "/Users/ringo/Repositories/stained-glass-factory/a.py", line 9, in <module> (Current frame)
    class A(Generic[P]):
  File "/Users/ringo/anaconda3/envs/glass38/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/ringo/anaconda3/envs/glass38/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
TypeError: Parameters to Generic[...] must all be type variables

This occurs because in the typing_extensions.ParamSpec for Python<3.10 :

class ParamSpec(list, _DefaultMixin):
    ...
    __class__ = typing.TypeVar

But when I set a breakpoint immediately after this definition and check ParamSpec("P").__class__, I see <class 'typing_extensions.ParamSpec'>. If I copy and paste the source code for ParamSpec in the debug console and try it again, it actually works as expected...

Expected behavior

I don't expect there to be an error in this class definition when debugging.

Steps to reproduce:

  1. Use conda for M1 and create an environment with python < 3.10
  2. activate and pip install typing_extensions
  3. Use VS Code for Apple Silicon
  4. Run the debugger with justMyCode: false and check User Uncaught Exceptions
  5. Debug the above code
@qthequartermasterman
Copy link

I am having the same issue on python==3.9 on M1 Mac.

Version: 1.80.2
Commit: 2ccd690cbff1569e4a83d7c43d45101f817401dc

@int19h int19h added the bug Something isn't working label Sep 12, 2023
@agustingomes-therapieland
Copy link

agustingomes-therapieland commented May 10, 2024

I am experiencing similar issues on a project I'm working, also on a M1 Mac, but in my case, it manifests when I use the PyCharm debugger with any Django's ./manage.py command.

I am fairly new to the Python ecosystem, so if you need more details about the environment, I'll be happy to provide them.

EDIT:

I used the same code snippet that @ringohoffman provided, and I have the same outcome, which then gives me the feeling this particular issue might not be solely related to this project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants