Skip to content

Commit

Permalink
Fix two types of issues raised by mypy - implicit optional issues and…
Browse files Browse the repository at this point in the history
… arg-type mismatch (#1234)

Summary:
Title. Here is the mypy run failing with 24 errors - https://github.com/pytorch/data/actions/runs/8428471909/job/23081016202.

With these two changes, the mypy errors are now down to 8 - https://github.com/pytorch/data/actions/runs/8428898766/job/23082258705?pr=1234

### Changes

- Add optional where it was implicit earlier
- Change ignore type to arg-type

Pull Request resolved: #1234

Reviewed By: ejguan

Differential Revision: D55350451

Pulled By: gokulavasan

fbshipit-source-id: 54a99c8879eaf84aea0fb833cbbd9f37bc504db9
  • Loading branch information
gokulavasan authored and facebook-github-bot committed Mar 26, 2024
1 parent 4725a01 commit 2b831b3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions torchdata/datapipes/iter/load/online.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _get_response_from_http(
) -> Tuple[str, StreamWrapper]:
with requests.Session() as session:
proxies = _get_proxies()
r = session.get(url, timeout=timeout, proxies=proxies, stream=True, **query_params) # type: ignore[attr-defined]
r = session.get(url, timeout=timeout, proxies=proxies, stream=True, **query_params) # type: ignore[arg-type]
r.raise_for_status()
return url, StreamWrapper(r.raw)

Expand Down Expand Up @@ -112,7 +112,7 @@ def _get_response_from_google_drive(
confirm_token = None

with requests.Session() as session:
response = session.get(url, timeout=timeout, stream=True, **query_params) # type: ignore[attr-defined]
response = session.get(url, timeout=timeout, stream=True, **query_params) # type: ignore[arg-type]
response.raise_for_status()

for k, v in response.cookies.items():
Expand All @@ -129,7 +129,7 @@ def _get_response_from_google_drive(
if confirm_token:
url = url + "&confirm=" + confirm_token

response = session.get(url, timeout=timeout, stream=True, **query_params) # type: ignore[attr-defined]
response = session.get(url, timeout=timeout, stream=True, **query_params) # type: ignore[arg-type]
response.raise_for_status()

if "content-disposition" not in response.headers:
Expand Down
2 changes: 1 addition & 1 deletion torchdata/datapipes/iter/util/cacheholder.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def __init__(
self,
source_datapipe: IterDataPipe,
filepath_fn: Optional[Callable] = None,
hash_dict: Dict[str, str] = None,
hash_dict: Optional[Dict[str, str]] = None,
hash_type: str = "sha256",
extra_check_fn: Optional[Callable[[str], bool]] = None,
):
Expand Down
6 changes: 4 additions & 2 deletions torchdata/datapipes/iter/util/rows2columnar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# LICENSE file in the root directory of this source tree.

from collections import defaultdict
from typing import Dict, Iterator, List, Union
from typing import Dict, Iterator, List, Optional, Union

from torchdata.datapipes import functional_datapipe
from torchdata.datapipes.iter import IterDataPipe
Expand Down Expand Up @@ -50,7 +50,9 @@ class Rows2ColumnarIterDataPipe(IterDataPipe[Dict]):
"""
column_names: List[str]

def __init__(self, source_datapipe: IterDataPipe[List[Union[Dict, List]]], column_names: List[str] = None) -> None:
def __init__(
self, source_datapipe: IterDataPipe[List[Union[Dict, List]]], column_names: Optional[List[str]] = None
) -> None:
self.source_datapipe: IterDataPipe[List[Union[Dict, List]]] = source_datapipe
self.column_names: List[str] = [] if column_names is None else column_names

Expand Down

0 comments on commit 2b831b3

Please sign in to comment.