Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions typesafety/test_upath_signatures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,13 @@

reveal_type(UPath.home()) # N: Revealed type is "upath.core.UPath"

- case: upath_classmethod_from_uri
disable_cache: false
main: |
from upath import UPath

reveal_type(UPath.from_uri("uri")) # N: Revealed type is "upath.core.UPath"

- case: upath_method_relative_to
disable_cache: false
main: |
Expand Down Expand Up @@ -1084,3 +1091,4 @@
# Class methods
reveal_type({{ cls }}.cwd()) # N: Revealed type is "{{ module }}.{{ cls }}"
reveal_type({{ cls }}.home()) # N: Revealed type is "{{ module }}.{{ cls }}"
reveal_type({{ cls }}.from_uri("uri")) # N: Revealed type is "{{ module }}.{{ cls }}"
4 changes: 4 additions & 0 deletions upath/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,10 @@ def __reduce__(self):
kwargs["_relative_base"] = self._relative_base
return _make_instance, (type(self), args, kwargs)

@classmethod
def from_uri(cls, uri: str, **storage_options: Any) -> Self:
return cls(uri, **storage_options)

def as_uri(self) -> str:
if self._relative_base is not None:
raise ValueError(
Expand Down
4 changes: 4 additions & 0 deletions upath/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ def root(self) -> str:
def __reduce__(self):
return type(self)._from_upath, (self.__wrapped__,)

@classmethod
def from_uri(cls, uri: str, **storage_options: Any) -> Self:
return cls(uri, **storage_options)

def as_uri(self) -> str:
return self.__wrapped__.as_uri()

Expand Down
4 changes: 4 additions & 0 deletions upath/implementations/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,10 @@ def full_match(self, pattern: str) -> bool:
# todo: revisit
return self.match(pattern)

@classmethod
def from_uri(cls, uri: str, **storage_options: Any) -> Self:
return UPath(uri, **storage_options) # type: ignore[return-value]

if sys.version_info < (3, 12):

def is_junction(self) -> bool:
Expand Down