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

UPath instance check #29

Closed
brl0 opened this issue Aug 4, 2021 · 0 comments
Closed

UPath instance check #29

brl0 opened this issue Aug 4, 2021 · 0 comments

Comments

@brl0
Copy link
Contributor

brl0 commented Aug 4, 2021

I think it would be nice if something like this worked:

from upath import UPath

path = UPath(".")
assert isinstance(path, UPath)  # this currently returns false

This issue occurs for local and remote paths, so for pathlib and UniversalPath objects.

Thanks to UPath and various implementations inheriting from pathlib.Path, here is one basic approach that seems to allow this to work:

from abc import ABCMeta


class UPathMeta(ABCMeta):
    def __instancecheck__(self, instance):
        return isinstance(instance, Path)

    def __subclasscheck__(self, subclass):
        return issubclass(subclass, Path)

class UPath(Path, metaclass=UPathMeta):
    ...

I am working to submit a PR for #25 and #26, so I am planning to also include this change, but can take it out if undesired or preferred in a separate PR.

brl0 added a commit to brl0/universal_pathlib that referenced this issue Aug 4, 2021
andrewfulton9 added a commit that referenced this issue Aug 9, 2021
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

No branches or pull requests

2 participants