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
add GroupedMetadata as a base class for Interval #12
Conversation
Codecov Report
@@ Coverage Diff @@
## main #12 +/- ##
==========================================
+ Coverage 95.77% 95.89% +0.11%
==========================================
Files 2 2
Lines 142 146 +4
Branches 35 36 +1
==========================================
+ Hits 136 140 +4
Misses 6 6
📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more |
Oh, very nice! I think that all this needs is documentation in the README as well as the lovely docstring. A few points to clarify:
After that, let's merge and release a new version! |
Sounds good to me. Can just add an
I think what you are saying is that What do you think of having |
@Zac-HD I'm terribly sorry I hit edit instead of quote on your comment, so I edited yours instead of posting my own. I restored it now |
Have to add the metaclass, which is most easily done by inheriting from
Yep.
That sounds good to me! That said, it seems useful to have a single checkable class. Maybe |
That sounds nice in theory, but I'm weary of creating class hierarchies if I don't really need them. It's really no more LOC or complexity for consumers to have two checks nested or at the same level (you need 2 anyway), I'll push that version in a few min |
Pushed. Like I said the difference is minor, there are always going to be 2 |
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.
Implementation LGTM, pending documentation.
Co-authored-by: Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
I started writing the docs and it felt a bit awkward because we don't really have any documentation discussing |
Sounds reasonable; could be a follow-up or part of this PR; I'm happy with either. If follow-up, I think this is ready to merge (though not release without docs). |
LGTM, my only concern is about use of abc, python/cpython#92810 - I basically live in fear of abs these days. But I guess in this situation it:
|
Sorry I merged right before your comment. Agreed on avoiding ABCs, but I think we couldn't do much here. Protocol would be a no-go because Protocol + isinstance isn't great either. We could always remove it and just manually raise a NotImplementedError or something. |
That was going to be my suggestion, then the page updated as the PR was merged :-). I think this is fine for now, surely abcs will have to be fixed in cpython soon + my above comments. |
If you feel strongly, we can still change it! |
(looks like re snuck back in somehow) Happy to do whatever on abc, so long as the error is raised when subclassing, not when you try to iterate. |
If we can do that, that's great with me. But is there a reliable (and fairly simple!) way to raise an error when defining subclass if a method hasn't been implemented? If not, let's leave it as-is. |
You can implement |
I'm not too worried about linters if we can get a fully-reliable runtime check, and it looks like |
I opened #16, we can continue that discussion there |
I like it enough to merge already 😆 |
The main idea here is to generalize the pattern in
Interval
so that Pydantic and similar can define theirField
as inheriting fromGroupedMetadata
, thus anything that can parseannotated-types
will know how to unpack it (if it is not already unpacked by the PEP-646) even if it is a custom subclass in a library likePydantic
.Without this, some generic
annotated-types
parser would not know how to handlePydantic
'sField
type without specific knowledge of Pydantic.