Skip to content

Stubgen generates reference to types.TracebackType without importing types #17037

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

Closed
henribru opened this issue Mar 16, 2024 · 4 comments · Fixed by #19120
Closed

Stubgen generates reference to types.TracebackType without importing types #17037

henribru opened this issue Mar 16, 2024 · 4 comments · Fixed by #19120
Labels
bug mypy got something wrong topic-stubgen

Comments

@henribru
Copy link
Contributor

henribru commented Mar 16, 2024

Bug Report

When stubgen generates annotations for __exit__, it references types.TracebackType without importing types

To Reproduce

Run stubgen on this file:

class Foo:
    def __exit__(
        self,
        type,
        value,
        traceback,
    ) -> None: ... 

Expected Behavior

import types

class Foo:
    def __exit__(self, type: type[BaseException] | None, value: BaseException | None, traceback: types.TracebackType | None) -> None: ...

Actual Behavior

class Foo:
    def __exit__(self, type: type[BaseException] | None, value: BaseException | None, traceback: types.TracebackType | None) -> None: ...

Notice that it uses types.TracebackType to annotate traceback, but doesn't add an import for types.

Your Environment

  • Mypy version used: 1.9.0
  • Mypy command-line flags: N/A
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.10.0
@henribru henribru added the bug mypy got something wrong label Mar 16, 2024
@makridenko
Copy link
Contributor

i guess this issue is no longer relevant

@henribru
Copy link
Contributor Author

i guess this issue is no longer relevant

Why do you say that? It seems to reproduce just fine still.

@makridenko
Copy link
Contributor

@henribru I tried to repeat this error with the actual code in the master branch, works as expected

@makridenko
Copy link
Contributor

@henribru my bad, the error is still there, I apologise.
I'll look into it.

sobolevn pushed a commit that referenced this issue May 21, 2025
Fixes #17037

Add import for `types` in `__exit__` method signature
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-stubgen
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy