`--createstub` can drop directories if a source file is named the same as its parent directory.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
Describe the bug
It appears that when using --createstub, if you ask for a stub to be created for a module that has the same name as the package it appears in, pyright will omit a directory from the path.
Code or Screenshots
Here's a simple example: set up a fake repo containing a directory path top_level/child/my_module. Within the my_module directory, add an __init__.py and a my_module.py file. The my_module.py file can be fairly trivial; here is the code I used for it:
class SomeClass:
field: int
In __init__.py, just import the SomeClass type like so:
from .my_module import SomeClass
Now, from the top level of the fake repo, run Pyright with:
pyright --createstub top_level.child.my_module.my_module
I expected to see that the typings directory would contain a path to a file at top_level/child/my_module/my_module.pyi. Instead, I see that while the path top_level/child/my_module exists, it is empty. Instead, I observe that the pyi file is at typings/top_level/my_module/my_module.pyi. The contents are correct, but import resolution won't work with it here.
If I remove __init__.py, I see the .pyi file generated at typings/top_level/top_level/child/my_module/my_module.pyi. The duplicated top level is odd, but I can work around that easily. Missing a directory in the middle is more difficult.
VS Code extension or command-line
I am on pyright version 1.1.399 and am running from the command line.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Pyright's command-line handling for --createstub and reproduce the issue using the top_level/child/my_module layout described. Trace how the module name becomes the typings path, then verify that the generated file is at typings/top_level/child/my_module/my_module.pyi and that import resolution works for the package.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100