Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@alexjbuck
Copy link
Contributor

@alexjbuck alexjbuck commented Jun 6, 2025

Thanks for adding type hints to s3path!

I saw your comments about type hints adding to the maintenance burden, and I don't want that to be the case because the benefit of type hints are great. This is a PR to address what I believe is an error in the type hint implementation added in 0.6.3.

Closes #198

This PR changes the return type of PureS3Path.from_uri and PureS3Path.from_bucket_key to be Self instead of PureS3Path. Both class methods return an instance of cls which is not necessarily a PureS3Path if the class method is invoked from a subclass.

# 0.6.3 type behavior
>> S3Path.from_uri('s3://bucket/key')
<< PureS3Path('/bucket/key')

>> PureS3Path.from_uri('s3://bucket/key')
<< PureS3Path('/bucket/key')

# Proposed type behavior
>> S3Path.from_uri('s3://bucket/key')
<< S3Path('/bucket/key')

>> PureS3Path.from_uri('s3://bucket/key')
<< PureS3Path('/bucket/key')

I believe this is the desired behavior because this allows construction of a concrete S3Path from a uri string.

The alternative is that PureS3Path.from_uri should only ever return a PureS3Path and not be allowed to return an S3Path or any other subclass of PureS3Path. If this is the case, instead of changing the return type hints, the implementation of the class methods should be changed to return a PureS3Path instead of cls.

@liormizr liormizr merged commit 222e01e into liormizr:master Jun 14, 2025
5 checks passed
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

Successfully merging this pull request may close these issues.

S3Path.from_uri returns a PureS3Path instead of S3Path

2 participants