Skip to content

Add py.typed#363

Merged
ValerianRey merged 2 commits intomainfrom
add-py-typed
May 28, 2025
Merged

Add py.typed#363
ValerianRey merged 2 commits intomainfrom
add-py-typed

Conversation

@ValerianRey
Copy link
Copy Markdown
Contributor

@ValerianRey ValerianRey commented May 28, 2025

When using mypy, I had an issue with qpsolvers:

src/torchjd/aggregation/_utils/dual_cone.py:5: error: Skipping analyzing "qpsolvers": module is installed, but missing library stubs or py.typed marker  [import-untyped]
src/torchjd/aggregation/_utils/dual_cone.py:5: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

I never knew about this, but PEP 561 asks package maintainers to add a py.typed file in their topmost package to indicate that the package's interface is type-hinted. Mypy will read this and analyze it only if a py.typed marker is present, or if the --follow-untyped-imports flag is provided.

So we actually have the same problem with torchjd itself! To verify this, I tried running mypy from arena, and I got the following error:

src/arena/interfaces.py:7: error: Skipping analyzing "torchjd.aggregation": module is installed, but missing library stubs or py.typed marker  [import-untyped]
src/arena/interfaces.py:7: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

For now, when building the torchjd package, everything (included this py.typed file) is included, so I think we don't have to change anything else (this seems to be the case since setuptools 69.0.

@ValerianRey ValerianRey added the cc: feat Conventional commit type for new features. label May 28, 2025
@ValerianRey ValerianRey self-assigned this May 28, 2025
@ValerianRey ValerianRey requested a review from PierreQuinton May 28, 2025 12:45
@codecov
Copy link
Copy Markdown

codecov bot commented May 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ValerianRey
Copy link
Copy Markdown
Contributor Author

ValerianRey commented May 28, 2025

Note that from arena, installing this branch (add-py-typed) of torchjd seems to fix the issue:

./setup_env.sh add-py-typed
uv pip install mypy
uv run mypy src/arena

=> No more [import-untyped] error.

So it works!

@ValerianRey ValerianRey merged commit 08cef61 into main May 28, 2025
16 checks passed
@ValerianRey ValerianRey deleted the add-py-typed branch May 28, 2025 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cc: feat Conventional commit type for new features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants