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

bpo-30247: Add os.PathLike handle for finder and loader #1422

Closed
wants to merge 6 commits into from
Closed

bpo-30247: Add os.PathLike handle for finder and loader #1422

wants to merge 6 commits into from

Conversation

louisom
Copy link
Contributor

@louisom louisom commented May 3, 2017

No description provided.

@mention-bot
Copy link

@lulouie, thanks for your PR! By analyzing the history of the files in this pull request, we identified @brettcannon, @serhiy-storchaka and @ericsnowcurrently to be potential reviewers.

@@ -802,7 +802,7 @@ def __init__(self, fullname, path):
"""Cache the module name and the path to the file found by the
finder."""
self.name = fullname
self.path = path
self.path = path.__fspath__() if hasattr(path, '__fspath__') else path
Copy link
Member

Choose a reason for hiding this comment

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

You can actually use _os.fspath() instead of this little trick.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, is _os, not os, ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@brettcannon why is some class meta using os at the top, but here we need to use _os?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@brettcannon I think we will still need to use this trick, the test cases including None, list and others , if we pass it to _os.fspath, it will raise the TypeError.

Copy link
Member

Choose a reason for hiding this comment

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

@lulouie can you point me at the tests that test for None and lists? And if accepting None is acceptable then you simply test for that case, e.g. os.fspath(path) if path is not None else None or something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@brettcannon There are some test about None, {} in unittest.

None: test_finder.py
{}: test_file_loader.py

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But they are using empty dict, do they accept something like {'a': path_a, 'b': path_b} ?

Copy link
Member

@brettcannon brettcannon left a comment

Choose a reason for hiding this comment

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

Removing the ExtensionFileLoader part lets you just test FileLoader and FileFinder.

@@ -23,9 +24,11 @@

EXTENSIONS = types.SimpleNamespace()
EXTENSIONS.path = None
EXTENSIONS.pathlike = None
Copy link
Member

Choose a reason for hiding this comment

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

These add attributes aren't really necessary as you can construct the pathlib instances on-demand.

@@ -802,7 +802,7 @@ def __init__(self, fullname, path):
"""Cache the module name and the path to the file found by the
finder."""
self.name = fullname
self.path = path
self.path = path.__fspath__() if hasattr(path, '__fspath__') else path
Copy link
Member

Choose a reason for hiding this comment

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

@lulouie can you point me at the tests that test for None and lists? And if accepting None is acceptable then you simply test for that case, e.g. os.fspath(path) if path is not None else None or something.

@@ -908,7 +908,7 @@ class ExtensionFileLoader(FileLoader, _LoaderBasics):

def __init__(self, name, path):
self.name = name
self.path = path
self.path = path.__fspath__() if hasattr(path, '__fspath__') else path
Copy link
Member

Choose a reason for hiding this comment

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

It's probably better to call super().__init__(name, path) than to duplicate this just for extension modules.

@@ -960,7 +960,7 @@ class _NamespacePath:

def __init__(self, name, path, path_finder):
self._name = name
self._path = path
self._path = path.__fspath__() if hasattr(path, '__fspath__') else path
Copy link
Member

Choose a reason for hiding this comment

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

This should be reverted as _NamespacePath is private and this affects what is valid for __path__ which I'm not prepared to change.

@@ -1203,7 +1203,7 @@ def __init__(self, path, *loader_details):
loaders.extend((suffix, loader) for suffix in suffixes)
self._loaders = loaders
# Base (directory) path
self.path = path or '.'
self.path = path.__fspath__() if hasattr(path, '__fspath__') else path or '.'
Copy link
Member

Choose a reason for hiding this comment

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

This should become a multi-line statement as there's too much going on to keep it a single line (even if you do switch to _os.fspath() as that or is not obvious anymore).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what about _os.fspath(path) if path else '.'?

@louisom
Copy link
Contributor Author

louisom commented May 5, 2017

@brettcannon so the PathLike test only needs to deal with test_importlib/*.py, but other in the folder (extension, frozen, import_, source) no need to do it, right?

@brettcannon
Copy link
Member

Yep, testing FileFinder and FileLoader directly is enough (if you really want to test all the subclasses quickly and simply that's fine too, but don't complicate any of the testing infrastructure to do it).

And this will require a doc update and a mention in Misc/NEWS, but as can worry about that once we're happy with the code.

@brettcannon
Copy link
Member

To try and help move older pull requests forward, we are going through and backfilling 'awaiting' labels on pull requests that are lacking the label. Based on the current reviews, the best we can tell in an automated fashion is that a core developer requested changes to be made to this pull request.

If/when the requested changes have been made, please leave a comment that says, I have made the requested changes; please review again. That will trigger a bot to flag this pull request as ready for a follow-up review.

@tonybaloney
Copy link
Contributor

The branch for this PR has been deleted. This PR can be closed. @brettcannon

@brettcannon brettcannon closed this May 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants