-
Notifications
You must be signed in to change notification settings - Fork 54
Add py.typed marker for PEP 561 type checker support #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
benaduo
wants to merge
2
commits into
inertiajs:main
Choose a base branch
from
benaduo:fix/add-py-typed-marker
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from pathlib import Path | ||
| from unittest import TestCase | ||
|
|
||
|
|
||
| class PyTypedTestCase(TestCase): | ||
| def test_py_typed_marker_exists(self): | ||
| """Verify that the py.typed marker file exists for PEP 561 compliance.""" | ||
| package_dir = Path(__file__).resolve().parent.parent | ||
| py_typed = package_dir / "py.typed" | ||
| self.assertTrue( | ||
| py_typed.exists(), | ||
| f"py.typed marker file is missing from {package_dir}", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
[tool.poetry.include]section syntax is incorrect. Theincludekey should be placed directly under the[tool.poetry]section, not in a separate section. The current configuration will not work as intended and the py.typed file will not be included in the package distribution.The correct configuration should be:
Move the
includeline to be directly under[tool.poetry]and remove the[tool.poetry.include]header.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be correct, after doing more research, I’ve removed the [tool.poetry.include] section entirely. Poetry already includes files that live inside the declared package directory, and py.typed lives inside inertia/, which is already configured as a package, so it gets packaged automatically. The fix has been pushed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it include the py.typed file though? I think by default it only includes python files in the specified directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @sopelj, good question, I looked into this carefully.
Poetry includes all files in the package source tree by default, not just .py files. Since py.typed lives inside inertia/ which is already declared as a package, it ships in both the sdist and wheel automatically with no extra configuration needed.
This is confirmed by Jürgen Gmach (a well-known Python packaging contributor):
"Poetry actually includes everything that's part of the package source tree in your distribution, so py.typed is included out-of-the-box, no configuration needed."
Reference: https://jugmac00.github.io/blog/bite-my-shiny-type-annotated-library/
The confusion often comes from older Poetry issues (pre-1.0) where setup.py-based builds had this problem, but those are long resolved with the current poetry-core build backend.
If you have anything that contradicts this, I'm genuinely curious drop it in the next comment. I've gone through quite a bit of documentation on this and this is consistently what I find.
WORTH NOTING: This is also why I corrected my earlier commit to remove the [tool.poetry.include] section, py.typed comes packaged automatically, so the explicit include was unnecessary. That was the Copilot comment I addressed. If that's what you were referring to, then yes, it's already handled and the old PR has been updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks for the information. I have never used poetry personally. The other tools I've used only load Python files automatically. So thanks for the clarification. :)