-
Notifications
You must be signed in to change notification settings - Fork 13
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
Extensibility of [Relative]JSONPointer classes? #103
Comments
Sounds reasonable; I assume you just want to change pointer instantiation in the On raising exception subclasses, I think rather than changing constructor signatures this could be encapsulated by the associated pointer classes, for example via an |
Yes. The idea of a more comprehensive extensibility shift, where (for example) the Making this change just within the
Yes, that makes more sense, I'm not sure what I was thinking with the constructor thing. It sounds like it's worth putting up a PR for this direction, so I'll do that :-) |
I forgot to bring up one thing: Sometimes I need to distinguish between errors during construction of a pointer and during evaluation. This is easy if handling errors close to the source, but if farther away there's sometimes a difference between handling or reporting a malformed pointer vs being unable to resolve a well-formed pointer with a particular JSON document. I usually do this with small exception class hierarchies to avoid having to regex match the error message. I see three possibilities here:
I would prefer option 2, but would be perfectly happy with option 1. These classes are small enough that changes in the error messages are relatively rare, and there aren't that many cases. I'd also happily do option 3, of course, but it feels like making a change to your interface for what are essentially stylistic preferences. |
Option 3 😁 I've just released 0.11 which should provide a better starting point for your proposed changes. You can now distinguish between construction and evaluation errors. I'd suggest |
Woo hoo! 🙏 🚀 |
@marksparkza 🤦 I'll get to that... it might take until the week after next |
Cool, no rush. Also, I've not forgotten all your other PRs! From mid-July I will have time to start looking at the more complex and interrelated ones. |
@marksparkza in the OAI/oascomply project, I find myself subclassing
jschon.JSONPointer
andjschon.RelativeJSONPointer
for smoother integration with other aspects of that project. This includes raising a subclass ofjschon.JSONPointerError
orjschon.RelativeJSONPointerError
that also subclasses the root ofoascomply
's exception hierarchy.This is, perhaps, a rather unusual use case, but it could be made easier and more performant with some very small changes:
[Relative]JSONPointer(...)
withtype(self)(...)
(or similar, if there's a better way to do that in Python3[Relative]JSONPointerError
as a constructor parameter, and raising it in place of the hardcoded exception classesI don't think this would require changing type hints since this involves subclassing rather than defining a protocol - in this use case, I want
jschon
code to treat my subclasses just as if they were thejschon
-provided classes.Is this something you would be interested in as a PR, or do you want to exclude this use case? I'll happily work with either, I just figured it was worth asking before investing in working around the current design.
The text was updated successfully, but these errors were encountered: