-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Is there any way that can transfer path string to pathlib.Path object? #260
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
Comments
Hi, You've added a type hint for your test_fire function, specifying that When you call You can make your function accept either a
This will give you the output:
FYI, pull request #251 adds the types to the helptext. This is not merged yet, but when it is you would see the pathlib type when you access the helptext like:
|
Hi, Michael. Thank you, anyway. |
Hi, this isn't a thing that is particular to Fire, it is the case for all of Python. In any Python project (whether they use Fire or not) you can pass any type to a function. This is called Duck Typing and the reason that Python uses it is that it makes functions more flexible. Python doesn't care what type you give it, so long as it can use that type in the way you want. For example, think about this function. The type hint says a
If you call Fire isn't my project, so this would not be my decision, but I think automatically converting types would be confusing since that would be different from the rest of Python. I know this can be confusing so feel free to ask any questions about how duck typing works. |
可以看看 typefire |
Try afire! Which is a fork of python-fire supporing type convert according to the type hint. |
I have some function that use pathlib.Path as argument, like following script
I simply test it with this.
I expect to get a
pathlib.Path
object rather thanstr
. Is there any way that I can do this?Thanks a lot.
The text was updated successfully, but these errors were encountered: