improve type hint for Package.files#904
Merged
radoering merged 1 commit intopython-poetry:mainfrom Dec 31, 2025
Merged
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideTightens the type hint for Package.files by introducing a dedicated TypedDict (PackageFile) describing the expected file and hash keys, and updating the Package.files attribute to use this more precise type. Class diagram for tightened typing of Package.filesclassDiagram
class PackageFile {
+str file
+str hash
}
class Package {
+Sequence~PackageFile~ files
}
Package "1" o-- "*" PackageFile
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider whether
PackageFileshould declare any optional keys (e.g. usingTypedDict(total=False)orNotRequired[...]) if real-worldself.filesentries sometimes omitfileorhash, otherwise this stricter type may not accurately reflect existing usage.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider whether `PackageFile` should declare any optional keys (e.g. using `TypedDict(total=False)` or `NotRequired[...]`) if real-world `self.files` entries sometimes omit `file` or `hash`, otherwise this stricter type may not accurately reflect existing usage.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
|
Member
Author
|
Yeah, but since it is poetry-core we had to vendor it. I tend to think that vendoring is not worth it just for this. |
e55ecb0 to
5482e60
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
It is a matter of weighing things up but I believe checking the keys is worth more than checking immutability.
See python-poetry/poetry#10673 for issues that the improved typing uncovered.
Summary by Sourcery
Improve typing of package file metadata on packages.
Enhancements: