Skip to content

Commit

Permalink
Updated pre-commit modules and applied fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Jun 6, 2024
1 parent 13681d5 commit dba7265
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.1
rev: v0.4.8
hooks:
- id: ruff
args: [--fix, --show-fixes]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
rev: v1.10.0
hooks:
- id: mypy
additional_dependencies:
Expand Down
14 changes: 7 additions & 7 deletions cbor2/_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def _decode_length(self, subtype: int, allow_indefinite: bool = False) -> int |
elif subtype == 31 and allow_indefinite:
return None
else:
raise CBORDecodeValueError("unknown unsigned integer subtype 0x%x" % subtype)
raise CBORDecodeValueError(f"unknown unsigned integer subtype 0x{subtype:x}")

def decode_uint(self, subtype: int) -> int:
# Major tag 0
Expand All @@ -294,7 +294,7 @@ def decode_bytestring(self, subtype: int) -> bytes:
length = self._decode_length(initial_byte & 0x1F)
if length is None or length > sys.maxsize:
raise CBORDecodeValueError(
"invalid length for indefinite bytestring chunk 0x%x" % length
f"invalid length for indefinite bytestring chunk 0x{length:x}"
)
value = self.read(length)
buf.append(value)
Expand All @@ -304,7 +304,7 @@ def decode_bytestring(self, subtype: int) -> bytes:
)
else:
if length > sys.maxsize:
raise CBORDecodeValueError("invalid length for bytestring 0x%x" % length)
raise CBORDecodeValueError(f"invalid length for bytestring 0x{length:x}")
elif length <= 65536:
result = self.read(length)
else:
Expand Down Expand Up @@ -350,7 +350,7 @@ def decode_string(self, subtype: int) -> str:
length = self._decode_length(initial_byte & 0x1F)
if length is None or length > sys.maxsize:
raise CBORDecodeValueError(
"invalid length for indefinite string chunk 0x%x" % length
f"invalid length for indefinite string chunk 0x{length:x}"
)

try:
Expand All @@ -363,7 +363,7 @@ def decode_string(self, subtype: int) -> str:
raise CBORDecodeValueError("non-string found in indefinite length string")
else:
if length > sys.maxsize:
raise CBORDecodeValueError("invalid length for string 0x%x" % length)
raise CBORDecodeValueError(f"invalid length for string 0x{length:x}")

if length <= 65536:
try:
Expand Down Expand Up @@ -405,7 +405,7 @@ def decode_array(self, subtype: int) -> Sequence[Any]:
items.append(value)
else:
if length > sys.maxsize:
raise CBORDecodeValueError("invalid length for array 0x%x" % length)
raise CBORDecodeValueError(f"invalid length for array 0x{length:x}")

items = []
if not self._immutable:
Expand Down Expand Up @@ -476,7 +476,7 @@ def decode_special(self, subtype: int) -> Any:
return special_decoders[subtype](self)
except KeyError as e:
raise CBORDecodeValueError(
"Undefined Reserved major type 7 subtype 0x%x" % subtype
f"Undefined Reserved major type 7 subtype 0x{subtype:x}"
) from e

#
Expand Down
2 changes: 1 addition & 1 deletion cbor2/_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def encode(self, obj: Any) -> None:
obj_type = obj.__class__
encoder = self._encoders.get(obj_type) or self._find_encoder(obj_type) or self._default
if not encoder:
raise CBOREncodeTypeError("cannot serialize type %s" % obj_type.__name__)
raise CBOREncodeTypeError(f"cannot serialize type {obj_type.__name__}")

encoder(self, obj)

Expand Down

0 comments on commit dba7265

Please sign in to comment.