Skip to content

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

Open
@henribru

Description

@henribru

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions