-
-
Notifications
You must be signed in to change notification settings - Fork 581
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
Support namedtuple #364
Comments
:/ that makes me a bit sad to see, but I've already been open to the idea that is_type's interface should be wider (it started narrow to drive out needing it to be wide, but it's likely getting to the point where now it needs to be -- draft 6 already poses some issues there). Will have to think about possible ways to widen it but I think this sounds reasonable. Suggestions welcome obviously, as well as certainly patches. |
Just moving the conversation from the PR (#370 (comment)) here to keep things more contained. I've had a little look at your suggestions [1]. I can certainly see the benefit in immutability and a Although The
Some additional complications:
[1] draft6...bsmithers:types |
Awesome! Progress looks great, really grateful you're persisting here! Gonna leave a few notes just on the first half of your comment, I need to read your code to be able to answer the "additional complication" section I suspect. Will try to do that ASAP.
Man... I don't even remember what the use case is for that. Will have to hunt down the original PR. In theory obviously you can still support that via
I'd prefer this as a separate API -- i.e. Your
I'd prefer an explicit API for this -- a private one on |
OK! Few more comments now after skimming the code:
So I'd move this outside of
I think it's OK here to have type checkers return
So I guess there's a historical answer (that But! I think it might still be a good idea to deprecate the Again, really appreciate the work! Think we're definitely headed in the right direction, lemme know what you think about all the above! |
Unfortunately that won't work. Keyword arguments must be strings.
Sure, works for me. I think we do want the multiple redefinition option though. To make the cleanest use of attr's With that in mind, we have
A really good point and I completely agree.
I'm not sure about either of these things. The return value of
Agreed. I'm pretty happy this is heading the right way now (thanks for all the input!) so I'll start trying to round this out with test coverage & documentation changes also. By the way, I've based this work on the draft6 branch - to me it makes sense to release the changed type interface alongside draft 6 support - but let me know if you'd prefer it rebased against master. |
Er yeah let's make believe I didn't say that :D, I wrote it off the cuff and was thinking of the similar case where you do have strings but they're keywords (e.g.
OK, fine with me too.
Sorry, I think I misunderstood what you meant here, although there's some ugliness here that I'm not sure I remembered :/ -- I think what you have is the best current solution, although it'll be super confusing to have 2 "unknown-type"-y exceptions... At very least we should document in both places clearly which one they'll raise, but yeah I don't have better ideas than that at the moment.
I think it'd help it get merged quicker since it would be independently doable, but either way I think is fine. |
Agreed. At least one of these is fairly "internal"; i.e. the new exception is either caught by the validator itself or only raised during "advanced" usage (definition of new TypeChecker).
Sure. I'm basically done with implementation & testing, so before I do the documentation changes I'll see how awkward the rebase is. |
Now that #374 is merged (and mostly cleaned up), something facilitating this should land in the next release! |
Though
json
doesn't treatnamedtuple
instances as objects,simplejson
does. It would be useful to be able to validate object graphs withnamedtuple
instances likedict
instances.The main complication here is that
Validator
'sis_type
andDEFAULT_TYPES
and very subclass-oriented, and detecting anamedtuple
is a matter of duck-typing (hasattr(instance.__class__, '_fields')
or the less-restrictivehasattr(instance, '_asdict')
). From there I'm not quite sure where to make the change to traverse object items.Thanks for your consideration.
The text was updated successfully, but these errors were encountered: