Skip to content

Types from typing turn into Unknown when typing module is imported with import as with a custom name AND overshadowed by a * import of another typing module import done in the same fashion #1854

Description

@dogtopus

Description

I know this smells like an anti-pattern and I personally don't like it, but the same pattern seems to work under Mypy and (older version of) Pyright so it gets hard to justify for a "fix" specifically for basedpyright and is probably worth looking into.


Minimum example: Refer below as Playground does not support multiple files.

Create 2 files in a Python package, common.py and repro.py

Content in common.py:

import typing as t

MyInt = t.NewType('MyInt', int)

Content in repro.py:

import typing as t  # Same name as the common import
from .common import *

reveal_type(t.Any)  # Type of "t.Any" is "Unknown"
reveal_type(MyInt)  # Type of "MyInt" is "type[MyInt]"

Does the issue also occur in Pyright? Doesn't seem like it. Tested under Pyright v1.1.402 (the last usable version available on open-vsx). Yes it does on Pyright v1.1.411 all vanilla config.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type checking / lintingissues relating to existing diagnostic rules or proposals for new diagnostic rules

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions