-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add strict support for mypy #169
base: main
Are you sure you want to change the base?
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.
I am not sure about these changes, they make the code harder to read and duplicate the constructor methods due to @overload
. What's the benefit for this?
@@ -17,8 +28,10 @@ | |||
|
|||
log = logging.getLogger(__name__) | |||
|
|||
T_co = TypeVar("T_co", covariant=True) |
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.
): | ||
) -> S3IterableDataset[S3Reader]: ... | ||
|
||
@overload |
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.
Do we want to introduce this overload just for typing?
|
||
from s3torchconnectorclient._mountpoint_s3_client import ObjectInfo, GetObjectStream | ||
|
||
|
||
class S3Reader(io.BufferedIOBase): | ||
class S3Reader(io.BufferedIOBase, IO[bytes]): |
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.
Why are we extending also IO[bytes]?
@@ -187,3 +188,12 @@ def writable(self) -> bool: | |||
bool: Return whether object was opened for writing. | |||
""" | |||
return False | |||
|
|||
def write(self, data: Any) -> int: |
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.
Similarly to these, shouldn't the writer throw on READ?
Also, I'd rather say "Not supported" as I don't think we'll implement write for S3Reader.
Description
Adds strict type checking with mypy. From the mypy guide, it says
I think this would be an ideal situation to be in, if possible. It does add extra work however when writing the code to ensure it type checks completely.
S3MapDataset
andS3IterableDataset
are now implemented as generics. This has no impact for customers not using type checking, but should improve IDE & mypy support.Additional context
Changes the constructor for
S3MapDataset
andS3IterableDataset
. These constructors are not public, so it's OK to change.Related items
Testing
mypy --strict s3torchconnector/src && mypy --strict s3torchconnectorclient/python/src
passesBy submitting this pull request, I confirm that my contribution is made under the terms of BSD 3-Clause License and I agree to the terms of the LICENSE.