Skip to content
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

Merged
merged 4 commits into from
Jun 7, 2018

Conversation

Shir0kamii
Copy link
Contributor

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.

@Shir0kamii
Copy link
Contributor Author

It seems the travis build is failing because:

  • pathlib is not available in 2.7
  • the package wheel is not available (anymore?) on 3.3

I can disable the pathlib feature if the import doesn't work, but I wouldn't know how to disable the test that comes with it. It was already difficult to understand how to set it up. @epsy Could you help me for that ? Also, I don't know what you might want to do with the second problem.

@epsy
Copy link
Owner

epsy commented May 25, 2018

Thanks for looking into it!

Exact type matches

I 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 support

I 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.3

Looks like it's time to retire it from supported versions. I'll tend to it tonight.

@coveralls
Copy link

coveralls commented May 25, 2018

Coverage Status

Coverage decreased (-0.2%) to 97.631% when pulling e47ebdd on Shir0kamii:feature/add-path-implicit-converter into 0dba12f on epsy:master.

@epsy
Copy link
Owner

epsy commented May 26, 2018

I removed 3.3 checks from master. If you rebase your branch the build won't fail on it.

@Shir0kamii Shir0kamii force-pushed the feature/add-path-implicit-converter branch 2 times, most recently from fd6f3f6 to a45d2af Compare May 29, 2018 13:33
@Shir0kamii Shir0kamii force-pushed the feature/add-path-implicit-converter branch 3 times, most recently from 97bfb37 to 5738191 Compare May 29, 2018 14:13
@Shir0kamii
Copy link
Contributor Author

@epsy All tests are passing!

@Shir0kamii
Copy link
Contributor Author

@epsy Is there anything else you might want ?

Copy link
Owner

@epsy epsy left a 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
Copy link
Owner

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

Copy link
Contributor Author

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)
Copy link
Owner

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.

Copy link
Contributor Author

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.

Copy link
Owner

@epsy epsy left a 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants