Open anriha opened 1 day ago
Hello 👋 @anriha,
Could you share your pyright CLI command or configuration file? I was unable to reproduce the error you mentioned. Since pyright is used by Pylance in VS Code, I didn't see the error there. To double-check, I also installed pyright via npm and ran it on a file I created using the same code you provided. The result was:
0 errors, 0 warnings, 0 informations.
Additionally, I added a simple pyright configuration to a toml file for testing purposes, and I got the same results.
[tool.pyright]
include = ["supervision"]
exclude = ["**/node_modules",
"**/__pycache__",
"**/.mypy_cache",
]
defineConstant = { DEBUG = true }
reportMissingImports = "error"
reportMissingTypeStubs = false
reportPrivateImportUsage = true
Unless you have an alternative approach, I will proceed to close this issue. We are also planning to fully integrate mypy to ensure the project is compatible with static typing. I should mention that pyright and mypy sometimes differ in how they interpret typing rules. Once we finalize the mypy configuration, we might need to make adjustments or add specific settings for pyright or Pylance to ensure compatibility. However, our primary guideline will be the mypy configuration.
For information here is mypy vs pyright: https://github.com/microsoft/pyright/blob/main/docs/mypy-comparison.md
cc @LinasKo
Thank you for looking into this. I'm still getting the error with just a basic pyright file.py
command:
# file.py
import supervision as sv
def process_detections(detections: sv.Detections) -> None:
pass
I don't have any specific pyright config, everything should be default. Did you test with supervision 0.25?
Thank you for looking into this. I'm still getting the error with just a basic
pyright file.py
command:# file.py import supervision as sv def process_detections(detections: sv.Detections) -> None: pass
I don't have any specific pyright config, everything should be default. Did you test with supervision 0.25?
Yes I tested with latest version of course
Just to check, I now created empty project with poetry. Only installed package is supervision. Installed pyright straight from npm (version 1.1.389). Still getting the same error.
Yep. Original error was from my IDE, but it gives me same error with just pyright file.py
To be completely sure I created following Dockerfile:
FROM python:3.12-slim
RUN apt-get update && apt-get install -y \
nodejs \
npm \
&& rm -rf /var/lib/apt/lists/*
RUN pip install supervision
RUN npm install -g pyright
WORKDIR /app
RUN echo 'import supervision as sv\n\ndef process_detections(detections: sv.Detections) -> None:\n pass' > test.py
CMD ["pyright", "test.py"]
Still getting the same error.
@anriha try this in your clean virtualenv and try again
pip install git+https://github.com/roboflow/supervision.git@typing/_all
Works without an error now :+1:
Search before asking
Bug
After supervision added
py.typed
support, Pyright is reporting areportPrivateImportUsage
error when trying to useDetections
type from the package's root import, even though it's explicitly re-exported in the package's__init__.py
.Environment
Supervision: 0.25.0 Python: 3.12.7 Pyright: 1.1.382 OS: NixOS
Minimal Reproducible Example
This triggers the error
Additional
The error can be temporarily worked around by using direct import:
from supervision.detection.core import Detections
Are you willing to submit a PR?