Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ repos:
- id: check-added-large-files
args: ['--maxkb=1000']

- repo: https://github.com/asottile/pyupgrade
rev: v3.21.2
hooks:
- id: pyupgrade
args: [--py310-plus]
files: ^(test|src)/
exclude: ^examples/

- repo: https://github.com/omnilib/ufmt
rev: v2.6.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@


import dataclasses
from collections.abc import Iterable, Iterator
from dataclasses import dataclass
from typing import Iterable, Iterator

from torch import Tensor

Expand Down
4 changes: 2 additions & 2 deletions src/torchcodec/decoders/_decoder_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

import contextvars
import io

from collections.abc import Generator
from contextlib import contextmanager
from pathlib import Path

from typing import Generator

from torch import Tensor
from torchcodec import _core as core

Expand Down
3 changes: 2 additions & 1 deletion src/torchcodec/decoders/_video_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import io
import json
import numbers
from collections.abc import Sequence
from pathlib import Path
from typing import Literal, Sequence
from typing import Literal

import torch
from torch import device as torch_device, nn, Tensor
Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/samplers/_common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable
from collections.abc import Callable

from torchcodec import FrameBatch

Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/transforms/_decoder_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@


from abc import ABC, abstractmethod
from collections.abc import Sequence
from types import ModuleType
from typing import Sequence

import torch
from torch import nn
Expand Down
6 changes: 3 additions & 3 deletions test/test_decoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_create_fails(self, Decoder):
# user mistakenly forgets to specify binary reading when creating a file
# like object from open()
with pytest.raises(TypeError, match="binary reading?"):
Decoder(open(NASA_VIDEO.path, "r"))
Decoder(open(NASA_VIDEO.path))


class TestVideoDecoder:
Expand Down Expand Up @@ -1334,7 +1334,7 @@ def test_custom_frame_mappings_json_and_bytes(
# Optionally open the custom frame mappings file if it is a file path
# or use a null context if it is a string.
with (
open(custom_frame_mappings, "r")
open(custom_frame_mappings)
if hasattr(custom_frame_mappings, "read")
else contextlib.nullcontext()
) as custom_frame_mappings:
Expand Down Expand Up @@ -1406,7 +1406,7 @@ def test_custom_frame_mappings_init_fails_invalid_json(self, tmp_path, device):
f.write("invalid input")

# Test both file object and string
with open(invalid_json_path, "r") as file_obj:
with open(invalid_json_path) as file_obj:
for custom_frame_mappings in [
file_obj,
file_obj.read(),
Expand Down
4 changes: 2 additions & 2 deletions test/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ def seek(self, offset: int, whence: int) -> int:

class SeekMethodMissing:
def read(self, size: int) -> bytes:
return bytes()
return b""

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

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

def seek(self, offset: int, whence: int) -> int:
return self._file.seeK(offset, whence)
Expand Down
2 changes: 1 addition & 1 deletion test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def __post_init__(self):
"You need to submit this file, or specify the `frames` field manually."
)

with open(frames_info_path, "r") as f:
with open(frames_info_path) as f:
frames_info = json.loads(f.read())
self.frames[stream_index] = {
frame_index: TestFrameInfo(
Expand Down
Loading