Skip to content

Commit 10246b9

Browse files
muddyfishIsaevIlya
authored andcommitted
Add type: ignore annotations in various places to make mypy pass (#168)
* Add `type: ignore` annotations in various places to make mypy pass * Install lightning extension for type checks * Add note about how to run mypy without lightning installed --------- Co-authored-by: Simon Beal <[email protected]>
1 parent 6e70fee commit 10246b9

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

.github/workflows/python-checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
python -m pip install flake8 black mypy
9898
python -m pip install torch --extra-index-url https://download.pytorch.org/whl/cpu
9999
python -m pip install ./s3torchconnectorclient
100-
python -m pip install ./s3torchconnector
100+
python -m pip install ./s3torchconnector[lightning]
101101
102102
- name: Lint with flake8
103103
run: |

doc/DEVELOPMENT.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ mypy s3torchconnectorclient/python/src
7575
```
7676
to lint.
7777

78+
To run mypy without `lightning` installed, run
79+
```bash
80+
mypy s3torchconnector/src --exclude s3torchconnector/src/s3torchconnector/lightning
81+
mypy s3torchconnectorclient/python/src
82+
```
83+
7884
### Debugging
7985

8086
Either a Python or GDB style debugger will be useful here.

s3torchconnector/src/s3torchconnector/lightning/s3_lightning_checkpoint.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ def __init__(self, region: str):
2424
def save_checkpoint(
2525
self,
2626
checkpoint: Dict[str, Any],
27-
path: str,
27+
# We only support `str` arguments for `path`, as `Path` is explicitly for local filesystems
28+
path: str, # type: ignore
2829
storage_options: Optional[Any] = None,
2930
) -> None:
3031
"""Save model/training states as a checkpoint file through state-dump and upload to S3.
@@ -41,7 +42,8 @@ def save_checkpoint(
4142

4243
def load_checkpoint(
4344
self,
44-
path: str,
45+
# We only support `str` arguments for `path`, as `Path` is explicitly for local filesystems
46+
path: str, # type: ignore
4547
map_location: Optional[Any] = None,
4648
) -> Dict[str, Any]:
4749
"""Load checkpoint from an S3 location when resuming or loading ckpt for test/validate/predict stages.
@@ -59,9 +61,15 @@ def load_checkpoint(
5961
self._validate_path(path)
6062
bucket, key = parse_s3_uri(path)
6163
s3reader = self._client.get_object(bucket, key)
62-
return torch.load(s3reader, map_location)
64+
# FIXME - io.BufferedIOBase and typing.IO aren't compatible
65+
# See https://github.com/python/typeshed/issues/6077
66+
return torch.load(s3reader, map_location) # type: ignore
6367

64-
def remove_checkpoint(self, path: str) -> None:
68+
def remove_checkpoint(
69+
self,
70+
# We only support `str` arguments for `path`, as `Path` is explicitly for local filesystems
71+
path: str, # type: ignore
72+
) -> None:
6573
"""Remove checkpoint file from the S3 uri.
6674
6775
Args:

0 commit comments

Comments
 (0)