microsoft / microsoft/pyright

ParamSpec allowed to be used before import

Open
#10,799 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
15.6k
Forks
1.8k
Avg merge
12h 13m
Merged PRs (30d)
52

Description

Note: if you are reporting a wrong signature of a function or a class in the standard library, then the typeshed tracker is better suited for this report: https://github.com/python/typeshed/issues.

If you have a question about typing or a behavior that you’re seeing in Pyright (as opposed to a bug report or enhancement request), consider posting to the [Pyright discussion forum](https://github.com/microsoft/pyright/discussions).

**Describe the bug**
In the event that the ParamSpec or TypeVar constructs are used prior to being imported from the typing module, they don't report an error if they are imported after their first use.

**Code or Screenshots**

```python
P = ParamSpec("P") # Should error, doesn't
R = TypeVar("R")

from typing import TypeVar, ParamSpec
```

**Pyright-playground link**

https://pyright-play.net/?code=AoAgvCwIYE5QtgZQA4FMDGAKARMbBKAWACgAlcEAFQE80A1WHUgkkgMxgHt4QAXWgJYA7AOYgB8ZJxi8qtVAxgAaSLAQoMJIA

**version of pyright**
pyright 1.1.403

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Pyright playground link and reproduce the example using pyright 1.1.403, checking the diagnostics before the later typing import. The issue is done when ParamSpec and TypeVar uses before their imports report errors consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.