-
Notifications
You must be signed in to change notification settings - Fork 43
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
Change subclassing behavior to Python standard #56
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I think valid isinstance
checks are quite helpful here! Returning the parent class in new
might still lead to confusion, but I think the current handling is more appropriate (see also the comment). Besides that I just have one minor nitpick:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS: I assume that if issubclass(cls, UPath):
in __new__
must always be True, no?
Theoretically, you can do |
@andrewfulton9 Are you ok with merging this? It kinda reverts #29, but I think it provides a more standard-compliant behavior. |
@normanrz, yeah, this looks good to me. I'll go ahead and merge and close it out. |
The current implementation makes it very hard to discern objects of
pathlib.Path
from objects ofUPath
(and its subclasses).This is due to the fact that
UPath
overwritesisinstance
andissubclass
checks in a meta class.In my user code, I currently discern between the two based on the existence of the
_kwargs
attribute.I think the current behavior is surprising and not very pythonic.
In this PR, I remove the multi-subclassing of
UPath
. This was unneccassary, because_flavour
can be implemented directly inUPath
andpathlib.Path
is a subclass ofpathlib.PurePath
itself. With that, I could also remove the meta classes.This PR also makes
upath
play more nicely with type checkers such asmypy
orpylance
.