@@ -602,25 +602,28 @@ class MyProtoPath(UPath):
602602 return args, protocol, storage_options
603603```
604604
605- #### Stopping UPath's subclass dispatch mechanism
605+ #### Extending UPath's API interface
606606
607- There are cases for which you want to disable the protocol dispatch mechanism of
608- the ` UPath.__new__ ` constructor. For example if you want to extend the class API
609- of your ` UPath ` implementation, and use it as the base class for other, directly
610- instantiated subclasses. Together with other customization options this can be a
611- useful feature. Please be aware that in this case all protocols are handled with
612- the default implementation in UPath. Please always feel free to open an issue in
613- the issue tracker to discuss your use case. We're happy to help with finding the
614- most maintainable solution.
607+ If you want to extend the class API
608+ of your ` UPath ` implementation, it's recommended to subclass
609+ ` upath.extensions.ProxyUPath ` . It's a thin proxy layer around
610+ the public methods and attributes of a UPath instance.
615611
616612``` python
617- class ExtraUPath (UPath ):
618- _protocol_dispatch = False # disable the registry return an ExtraUPath
613+ from upath.extensions import ProxyUPath
614+
615+ class ExtraUPath (ProxyUPath ):
619616
620617 def some_extra_method (self ) -> str :
621- return " hello world"
618+ return f " hello world { self .name} "
619+
620+ e0 = ExtraUPath(" s3://bucket/foo.txt" )
621+ e1 = ExtraUPath(" memory://bar/baz.txt" )
622622
623- assert ExtraUPath(" s3://bucket/file.txt" ).some_extra_method() == " hello world"
623+ assert e0.some_extra_method() == " hello world foo.txt"
624+ assert isinstance (e0, ExtraUPath)
625+ assert e1.some_extra_method() == " hello world baz.txt"
626+ assert isinstance (e1, ExtraUPath)
624627```
625628
626629## Migration Guide
@@ -729,6 +732,12 @@ path = UPath("memory:///file.txt")
729732os.remove(path) # TypeError: expected str, bytes or os.PathLike, not MemoryPath
730733```
731734
735+ #### Extending UPath via ` _protocol_dispatch=False `
736+
737+ If you previously used ` _protocol_dipatch=False ` to enable extension of the
738+ UPath API, we now recommend to subclass ` upath.extensions.ProxyUPath ` . See
739+ the example in the main docs.
740+
732741### migrating to ` v0.2.0 `
733742
734743### _ FSSpecAccessor subclasses with custom filesystem access methods
0 commit comments