microsoft / microsoft/pyright

Cannot import local type stub (.pyi)

Open
#11,414 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
15.6k
Forks
1.8k
Avg merge
12h 13m
Merged PRs (30d)
52

Description

**Describe the bug**
I'm trying to import a local typing stub (`lib.cryptox`="lib/cryptox.pyi")
But it's telling me "Import `lib.cryptox` could not be resolved from source" (I also tried just ".cryptox" but same thing)
When I added the whole lib directory as `"include"` in pyrightconfig.json, I was able to import it via `from cryptox import MT19937`

**Code or Screenshots**
lib/cryptox.pyi:
```python
from typing import Self

class MT19937:
STATE_LENGTH:int # readonly
STATE_M:int # readonly
MATRIX_A:int # readonly
TEMPERING_MASK_B:int
TEMPERING_MASK_C:int

def __init__(self,seed:int=None) -> None: ...
def init(self,seed:int) -> Self: ...
def s_rand(self,seed:int) -> None: ...
def rand(self) -> int: ...
```
lib/crypto.py:
```python
from lib.cryptox import MT19937

```

**VS Code extension or command-line**
VS Code extension

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the import in the VS Code extension using lib/cryptox.pyi, lib/crypto.py, and the existing pyrightconfig.json. Compare the failing lib.cryptox import with the working import after adding lib to include; done means the intended local stub import resolves without that workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.