Skip to content

Commit fb97dbd

Browse files
authored
Add pyupgrade to pre-commit hooks (#1104)
1 parent d76b289 commit fb97dbd

File tree

9 files changed

+21
-12
lines changed

9 files changed

+21
-12
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ repos:
1414
- id: check-added-large-files
1515
args: ['--maxkb=1000']
1616

17+
- repo: https://github.com/asottile/pyupgrade
18+
rev: v3.21.2
19+
hooks:
20+
- id: pyupgrade
21+
args: [--py310-plus]
22+
files: ^(test|src)/
23+
exclude: ^examples/
24+
1725
- repo: https://github.com/omnilib/ufmt
1826
rev: v2.6.0
1927
hooks:

src/torchcodec/_frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77

88
import dataclasses
9+
from collections.abc import Iterable, Iterator
910
from dataclasses import dataclass
10-
from typing import Iterable, Iterator
1111

1212
from torch import Tensor
1313

src/torchcodec/decoders/_decoder_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
import contextvars
99
import io
10+
11+
from collections.abc import Generator
1012
from contextlib import contextmanager
1113
from pathlib import Path
1214

13-
from typing import Generator
14-
1515
from torch import Tensor
1616
from torchcodec import _core as core
1717

src/torchcodec/decoders/_video_decoder.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
import io
99
import json
1010
import numbers
11+
from collections.abc import Sequence
1112
from pathlib import Path
12-
from typing import Literal, Sequence
13+
from typing import Literal
1314

1415
import torch
1516
from torch import device as torch_device, nn, Tensor

src/torchcodec/samplers/_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Callable
1+
from collections.abc import Callable
22

33
from torchcodec import FrameBatch
44

src/torchcodec/transforms/_decoder_transforms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77

88
from abc import ABC, abstractmethod
9+
from collections.abc import Sequence
910
from types import ModuleType
10-
from typing import Sequence
1111

1212
import torch
1313
from torch import nn

test/test_decoders.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def test_create_fails(self, Decoder):
127127
# user mistakenly forgets to specify binary reading when creating a file
128128
# like object from open()
129129
with pytest.raises(TypeError, match="binary reading?"):
130-
Decoder(open(NASA_VIDEO.path, "r"))
130+
Decoder(open(NASA_VIDEO.path))
131131

132132

133133
class TestVideoDecoder:
@@ -1334,7 +1334,7 @@ def test_custom_frame_mappings_json_and_bytes(
13341334
# Optionally open the custom frame mappings file if it is a file path
13351335
# or use a null context if it is a string.
13361336
with (
1337-
open(custom_frame_mappings, "r")
1337+
open(custom_frame_mappings)
13381338
if hasattr(custom_frame_mappings, "read")
13391339
else contextlib.nullcontext()
13401340
) as custom_frame_mappings:
@@ -1406,7 +1406,7 @@ def test_custom_frame_mappings_init_fails_invalid_json(self, tmp_path, device):
14061406
f.write("invalid input")
14071407

14081408
# Test both file object and string
1409-
with open(invalid_json_path, "r") as file_obj:
1409+
with open(invalid_json_path) as file_obj:
14101410
for custom_frame_mappings in [
14111411
file_obj,
14121412
file_obj.read(),

test/test_ops.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ def seek(self, offset: int, whence: int) -> int:
10051005

10061006
class SeekMethodMissing:
10071007
def read(self, size: int) -> bytes:
1008-
return bytes()
1008+
return b""
10091009

10101010
with pytest.raises(RuntimeError, match="must implement a seek method"):
10111011
create_from_file_like(SeekMethodMissing(), "approximate")
@@ -1016,7 +1016,7 @@ def __init__(self, file: io.RawIOBase):
10161016

10171017
# io.RawIOBase says we should accept a single int; wrong signature on purpose
10181018
def read(self) -> bytes:
1019-
return bytes()
1019+
return b""
10201020

10211021
def seek(self, offset: int, whence: int) -> int:
10221022
return self._file.seeK(offset, whence)

test/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def __post_init__(self):
262262
"You need to submit this file, or specify the `frames` field manually."
263263
)
264264

265-
with open(frames_info_path, "r") as f:
265+
with open(frames_info_path) as f:
266266
frames_info = json.loads(f.read())
267267
self.frames[stream_index] = {
268268
frame_index: TestFrameInfo(

0 commit comments

Comments
 (0)