Open oguzhanmeteozturk opened 1 month ago
sorry i'm not really familiar with cython or mypyc. is the issue that basedpyright is checking compiled code? if so, does excluding those files by adding them to exclude
solve the problem?
if that's not the issue, my follow up questions:
__init__.py
, foo.py
and bar.py
?.so
file?reportShadowedImports
because it's disabled by default in pyright)thanks
When using basedpyright's
reportShadowedImports
rule in projects compiled with Cython or mypyc, there are recurring false positives where it incorrectly flags project-specific files as overriding standard library modules (e.g.,typing
,copy
). This behavior impacts compiled Python projects, where the original source and the compiled modules coexist.Context:
Projects that compile Python code using tools like Cython and mypyc often include both the compiled output (e.g.,
.so
or.pyd
files) and the original Python source files (e.g.,.py
) in the src directory or a build directory within the project. During this process, basedpyright appears to misinterpret these files as "shadowing" or overriding standard library modules, which isn't the case in a properly configured project.Problem:
The issue typically manifests with false positives like:
__init__.py is overriding the stdlib module "typing"
__init__.py is overriding the stdlib module "copy"
__init__.py is overriding the stdlib module "itertools"
basedpyright is detecting the compiled modules as if they were replacing core Python libraries, even though no actual replacement or interference with the standard library is happening at runtime. This causes unnecessary noise, making it harder to differentiate real issues from false positives.
Expected Behavior:
In projects using Cython, mypyc, or similar tools, basedpyright should recognize that the compiled modules are not overriding or shadowing standard library modules. The current shadowing detection fails to account for the context in which the compiled modules exist.
Example:
Consider a project that has a structure like this after compilation:
In this case, basedpyright reports false positives after compilation even though the compiled modules are just importing modules and do not replace or interfere with the actual standard library modules, or use the same module name.
Proposed Solution:
This enhancement would reduce noise and improve accuracy for developers working on compiled Python projects without losing the benefits of static analysis.
Thank you for considering this issue, and for all the excellent work on basedpyright!