roboflow / supervision

We write your reusable computer vision tools. 💜
https://supervision.roboflow.com
MIT License
24.29k stars 1.8k forks source link

Pyright reportPrivateImportUsage error on supervision.Detections #1681

Open anriha opened 1 day ago

anriha commented 1 day ago

Search before asking

Bug

After supervision added py.typed support, Pyright is reporting a reportPrivateImportUsage error when trying to use Detections 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

import supervision as sv
def process_detections(detections: sv.Detections) -> None:
    pass

This triggers the error

def process_detections(detections: sv.Detections) -> None:
    pass

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?

onuralpszr commented 13 hours 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

anriha commented 13 hours ago

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?

onuralpszr commented 13 hours ago

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

anriha commented 12 hours ago

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.

anriha commented 12 hours ago

Yep. Original error was from my IDE, but it gives me same error with just pyright file.py

anriha commented 12 hours ago

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.

onuralpszr commented 12 hours ago

@anriha try this in your clean virtualenv and try again

pip install git+https://github.com/roboflow/supervision.git@typing/_all

anriha commented 12 hours ago

Works without an error now :+1: