Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switched from flake8+isort+pyupgrade to ruff #173

Closed
wants to merge 2 commits into from
Closed
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
30 changes: 5 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,13 @@ repos:
args: [ "--fix=lf" ]
- id: trailing-whitespace

- repo: https://github.com/asottile/pyupgrade
rev: v3.3.2
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.278
hooks:
- id: pyupgrade
args: [ "--py37-plus" ]
- id: ruff
args: [--fix, --show-fixes]

- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.7.0
hooks:
- id: black

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/csachs/pyproject-flake8
rev: v6.0.0.post1
hooks:
- id: pyproject-flake8

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-blanket-type-ignore
- id: python-no-eval
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal
4 changes: 2 additions & 2 deletions cbor2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)

try:
from _cbor2 import * # noqa: F401,F403
from _cbor2 import * # noqa: F403
except ImportError:
# Couldn't import the optimized C version; ignore the failure and leave the
# pure Python implementations in place.
Expand All @@ -30,7 +30,7 @@ def _init_cbor2():
import _cbor2

from .encoder import canonical_encoders, default_encoders
from .types import CBORSimpleValue, CBORTag, undefined # noqa: F8
from .types import CBORSimpleValue, CBORTag, undefined # noqa: F811

_cbor2.default_encoders = OrderedDict(
[
Expand Down
2 changes: 1 addition & 1 deletion cbor2/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def encode_shared(self, encoder, value):
self.encode_int(index)
else:
raise CBOREncodeValueError(
"cyclic data structure detected but value sharing is " "disabled"
"cyclic data structure detected but value sharing is disabled"
)

def _stringref(self, value):
Expand Down
18 changes: 10 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ benchmarks = [
[tool.setuptools.packages.find]
include = ["cbor2"]

[tool.isort]
src_paths = ["src"]
skip_gitignore = true
profile = "black"

[tool.flake8]
max-line-length = 99
exclude = ".tox,build,docs"
[tool.ruff]
line-length = 99
select = [
"E", "F", "W", # default flake-8
"I", # isort
"ISC", # flake8-implicit-str-concat
"PGH", # pygrep-hooks
"RUF100", # unused noqa (yesqa)
"UP", # pyupgrade
]

[tool.pytest.ini_options]
addopts = "-rsx --cov --tb=short"
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import platform
import struct

import pytest

import cbor2.decoder
import cbor2.encoder
import cbor2.types
import pytest

load_exc = ""
try:
Expand Down
3 changes: 2 additions & 1 deletion tests/hypothesis_strategies.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from collections import OrderedDict, defaultdict
from datetime import timedelta, timezone

from cbor2.types import FrozenDict
from hypothesis import strategies

from cbor2.types import FrozenDict

# Tune these for test run time
MAX_SIZE = 5
MAX_LEAVES = 2
Expand Down
9 changes: 6 additions & 3 deletions tests/test_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from uuid import UUID

import pytest

from cbor2.types import FrozenDict


Expand Down Expand Up @@ -40,7 +41,7 @@ def test_tag_hook_attr(impl):
decoder = impl.CBORDecoder(stream)

def tag_hook(decoder, tag):
return None # noqa: E731
return None

decoder.tag_hook = tag_hook
assert decoder.tag_hook is tag_hook
Expand All @@ -55,7 +56,7 @@ def test_object_hook_attr(impl):
decoder = impl.CBORDecoder(stream)

def object_hook(decoder, data):
return None # noqa: E731
return None

decoder.object_hook = object_hook
assert decoder.object_hook is object_hook
Expand Down Expand Up @@ -526,7 +527,9 @@ def test_ipaddress(impl, payload, expected):
def test_bad_ipaddress(impl):
with pytest.raises(impl.CBORDecodeError) as exc:
impl.loads(unhexlify("d9010443c00a0a"))
assert str(exc.value).endswith("invalid ipaddress value %r" % b"\xc0\x0a\x0a")
assert str(exc.value).endswith(
"invalid ipaddress value {!r}".format(b"\xc0\x0a\x0a")
)
assert isinstance(exc, ValueError)
with pytest.raises(impl.CBORDecodeError) as exc:
impl.loads(unhexlify("d9010401"))
Expand Down
3 changes: 2 additions & 1 deletion tests/test_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
from uuid import UUID

import pytest
from hypothesis import given

from cbor2 import shareable_encoder
from cbor2.types import FrozenDict
from hypothesis import given

from .hypothesis_strategies import compound_types_strategy

Expand Down
3 changes: 2 additions & 1 deletion tests/test_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import json
from io import BytesIO, TextIOWrapper

import cbor2.tool
import pytest

import cbor2.tool


@pytest.mark.parametrize(
"value, expected",
Expand Down
1 change: 1 addition & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest

from cbor2.types import FrozenDict


Expand Down
Loading