Explicit attribute type annotations#825
Merged
Merged
Conversation
Owner
|
ha nice thanks! I guess this is how one sees by how much structlog predates type hints. Given the dynamic nature of structlog, it was a PITA to add in the first place. What kinds of annotations are missing still?
I cried a little bit 🥲 |
Contributor
Author
I've been working on improving static typing in NumPy for 2 years now, so I feel you 😅 |
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.
Summary
Hi there,
I see that you're serious about static typing here; awesome!
When I ran
pyrefly coverage checkon the codebase, I noticed some opportunities for improvements because the reported type coverage (on main) is 93.49% (or 95.23% if you only consider the public API with--public-only).So I figured I might as well contribute, and well, here I am 🤷.
This adds explicit type annotations for the instance attributes, so that there's no need anymore to hope that all type-checkers infer the same intended types for them.
With this, the type coverage increased by +3.2% for a grand total of 96.68% (or with +3.66% to 98.89% with
--public-only) 🎉.These attribute annotations can also be considered as a form of documentation, because now you can easily see what attributes a certain class has and what their types are, without having to find the
__init__parse manually parse the logic in there.Pull Request Checklist
mainbranch.api.py.docs/api.rstby hand.versionadded,versionchanged, ordeprecateddirectives..rstand.mdfiles is written using semantic newlines.No AI was used; not even a little bit :)
I'm not sure if this is something you thing is worth putting in the changelog, so let me know if I should.