-
Notifications
You must be signed in to change notification settings - Fork 26
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
Allow to use pathlib.Path as implicit converter #47
Allow to use pathlib.Path as implicit converter #47
Conversation
It seems the travis build is failing because:
I can disable the |
Thanks for looking into it! Exact type matchesI think you should add a fallback in get_value_converter(typ) when the type is not marked as a value converter and is not directly in _implicit coverters. You could loop through _implicit_converters until one is a superclass. How would this affect paths that are specifically meant for another path system (e.g. for remote operation) ? 2.7 supportI saw that there was pathlib2 on PyPI. I'd suggest importing each of them and adding them to _implicit_converters in try blocks. Python 3.3Looks like it's time to retire it from supported versions. I'll tend to it tonight. |
I removed 3.3 checks from master. If you rebase your branch the build won't fail on it. |
fd6f3f6
to
a45d2af
Compare
97bfb37
to
5738191
Compare
@epsy All tests are passing! |
@epsy Is there anything else you might want ? |
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.
More time :)
I've requested a couple more changes, after that you're good.
clize/parser.py
Outdated
try: | ||
import pathlib2 as pathlib | ||
except ImportError: | ||
pathlib = False |
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.
None
would be more appropriate here
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.
You're right, the change is made
clize/parser.py
Outdated
if getattr(annotation, '_clize__value_converter', False): | ||
return annotation | ||
if not isinstance(annotation, type): | ||
annotation = type(annotation) |
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.
This makes it so that any callable (see line 827)'s type, instead of types themselves would be considered a converter. This seems unnecessarily broad. Is there a reason for it?
This is already the behavior for default parameters, by the way.
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.
I put it there because of a test not passing but it seems I misunderstood what to do.
The issubclass
call expect a type as argument, and I thought an instance was being passed. Instead it was a callable that should raise a ValueError.
So instead of this, I only run the fallback if the annotation is a type.
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.
Thank you for the patch, will merge tonight
Hi, as said during the paris.py meeting, I'm trying to solve #43 with this PR.
I tried using
pathlib.PurePath
as key like you suggested, but it is not looked up since concrete objects are not of the same type.