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

Slash notation causes mypy to throw an error #469

Open
HWiese1980 opened this issue Sep 4, 2024 · 1 comment
Open

Slash notation causes mypy to throw an error #469

HWiese1980 opened this issue Sep 4, 2024 · 1 comment

Comments

@HWiese1980
Copy link

cloudpathlib: 0.19.0
Python: 3.12
mypy: 1.11.2

When doing the following:

path = cloudpathlib.S3Path("s3://somebucket") / some_string / some_path / something_else

Mypy throws the following error:

error: Unsupported operand types for / ("S3Path" and "AnyPath") [operator]
error: Unsupported operand types for / ("S3Path" and "S3Path") [operator]
note: Right operand is of type "Path | CloudPath | AnyPath | S3Path"
error: Unsupported left operand type for / ("None")  [operator]
note: Left operand is of type "Path | S3Path | None"

In my opinion this is valid code. The result obviously ought to be an S3Path object merged from the original S3Path object, a string, another path-like object (could be a relative PosixPath even) and something totally different, as long as it can be interpreted as a path component.

@pjbull
Copy link
Member

pjbull commented Sep 4, 2024

Do you have any more detail? I believe that right hand str and relative PurePosixPath types should work.

The typing looks right to me for the div operator:

def __truediv__(self, other: Union[str, PurePosixPath]) -> Self:
if not isinstance(other, (str, PurePosixPath)):
raise TypeError(f"Can only join path {repr(self)} with strings or posix paths.")
return self._dispatch_to_path("__truediv__", other)

Since all cloud paths are absolute, we don't allow this kind of operation:

CloudPath("s3://bucket1/a/b.txt") / CloudPath("s3://bucket2/a/c.txt")

This would just return the right hand operand, which we think in more cases would be confusing than helpful (presumably, if you are trying to join the paths you want them to be put together).

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