8000 Allow model_spec to be provided as Path by taldcroft · Pull Request #99 · sot/xija · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Allow model_spec to be provided as Path #99

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

Merged
merged 1 commit into from
Oct 13, 2020
Merged

Allow model_spec to be provided as Path #99

merged 1 commit into from
Oct 13, 2020

Conversation

taldcroft
Copy link
Member

Description

Fixes #98 and removes some Py2 compatibility, and some whitespace changes tossed in by VS code.

Testing

  • Passes unit tests on MacOS
  • [N/A] Functional testing

Fixes #98

@taldcroft taldcroft requested a review from jeanconn October 13, 2020 13:18
# If model_spec supplied as a string then read model spec as a dict
if isinstance(model_spec, six.string_types):
# If model_spec is a str or Path then read that file
if isinstance(model_spec, (str, Path)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me. I can't think of a use case where we'd have something that was recognized as a in six.string_types that wouldn't be fine as a str. I think my previous question still stands though, are there other classes that would be just as reasonable for a "thing to read for the model spec" as a Path or a str? And if so, should this just try the read and work by duck typing or does the explicit handling here cover all reasonable cases? Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is always that question. I actually spent some time looking at open and the os.PathLike protocol. So you are right that a more perfect solution is a try/except after determining that the input model_spec is not None and not a dict (but what if it is a dict-like object that doesn't inherit from dict??). Except that it ends up being more complex code.

In the end I think this is good enough, and if not we'll fix it then. The user base for this class is quite small.

Copy link
8000 Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the conversation about it.

@taldcroft taldcroft requested a review from jeanconn October 13, 2020 20:18
@taldcroft taldcroft merged commit df693db into master Oct 13, 2020
@taldcroft taldcroft deleted the allow-path branch October 13, 2020 20:25
@javierggt javierggt mentioned this pull request Dec 7, 2020
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.

Allow pathlib Path/PosixPath as model_spec
2 participants
0