Skip to content

Commit

Permalink
flake8: Check for trailing commas
Browse files Browse the repository at this point in the history
  • Loading branch information
nbraud committed Feb 24, 2019
1 parent d603255 commit f7429e5
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 18 deletions.
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
flake8
flake8-bugbear
flake8-commas
hypothesis
mypy==0.641
perf
Expand Down
2 changes: 1 addition & 1 deletion ppb_vector/vector2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from math import atan2, cos, degrees, hypot, isclose, radians, sin, copysign, sqrt
from collections.abc import Sequence, Mapping

__all__ = 'Vector2',
__all__ = ('Vector2',)


# Vector or subclass
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[flake8]
select = E,F,W,B,B9
select = C,E,F,W,B,B9
ignore = E704
max-line-length = 100
4 changes: 2 additions & 2 deletions tests/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class V(Vector2):


@pytest.mark.parametrize(
"vector_like", vector_likes(), ids=lambda x: type(x).__name__
) # type: ignore
"vector_like", vector_likes(), ids=lambda x: type(x).__name__,
)
@pytest.mark.parametrize("cls", [Vector2, V]) # type: ignore
def test_convert_class(cls, vector_like):
vector = cls.convert(vector_like)
Expand Down
4 changes: 1 addition & 3 deletions tests/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ def test_monop(op, x):
reject()


@pytest.mark.parametrize(
"op", BINARY_OPS + BINARY_SCALAR_OPS + BOOL_OPS # type: ignore
)
@pytest.mark.parametrize("op", BINARY_OPS + BINARY_SCALAR_OPS + BOOL_OPS) # type: ignore
@given(x=vectors(), y=units())
def test_binop_vectorlike(op, x: Vector2, y: Vector2):
"""Test that `op` accepts a vector-like second parameter."""
Expand Down
10 changes: 4 additions & 6 deletions tests/test_vector2_isclose.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ def test_isclose_to_self(x, abs_tol, rel_tol):
EPSILON = 1e-8


@given(
x=vectors(max_magnitude=1e30), direction=units(), abs_tol=lengths(max_value=1e30)
)
@given(x=vectors(max_magnitude=1e30), direction=units(), abs_tol=lengths(max_value=1e30))
def test_isclose_abs_error(x, direction, abs_tol):
"""Test x.isclose(rel_tol=0) near the boundary between “close” and “not close”
Expand Down Expand Up @@ -64,8 +62,8 @@ def test_isclose_rel_error(x, direction, rel_tol):

positive = x + (1 - sqrt(EPSILON)) * x.length * error
note(
f"positive example: {positive} = x + {positive - x} ="
f"x + {(positive - x).length / x.length} * |x| * direction"
f"positive example: {positive} = x + {positive - x} = "
f"x + {(positive - x).length / x.length} * |x| * direction",
)

assert x.isclose(positive, abs_tol=0, rel_tol=rel_tol)
Expand All @@ -88,7 +86,7 @@ def test_isclose_rel_error(x, direction, rel_tol):
negative = x + (1 + sqrt(EPSILON)) * max(x.length, δ) * error
note(
f"negative example: {negative} = x + {negative - x} = "
f"x + {(negative - x).length / x.length} * |x| * direction"
f"x + {(negative - x).length / x.length} * |x| * direction",
)

assert not x.isclose(negative, abs_tol=0, rel_tol=rel_tol)
Expand Down
4 changes: 1 addition & 3 deletions tests/test_vector2_reflect.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
)


@pytest.mark.parametrize(
"initial_vector, surface_normal, expected_vector", reflect_data
)
@pytest.mark.parametrize("initial_vector, surface_normal, expected_vector", reflect_data)
def test_reflect(initial_vector, surface_normal, expected_vector):
assert initial_vector.reflect(surface_normal).isclose(expected_vector)

Expand Down
3 changes: 2 additions & 1 deletion tests/test_vector2_scalar_multiplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def test_scalar_associative(scalar1: float, scalar2: float, x: Vector2):
@given(scalar=floats(), x=vectors(), y=vectors())
def test_scalar_linear(scalar: float, x: Vector2, y: Vector2):
assert (scalar * (x + y)).isclose(
scalar * x + scalar * y, rel_to=[x, y, scalar * x, scalar * y]
scalar * x + scalar * y,
rel_to=[x, y, scalar * x, scalar * y],
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_vector2_truncate.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_truncate_invariant(x: Vector2, max_length: float):

@given(x=vectors(max_magnitude=1e150), max_length=floats())
@example( # Large example where x.length == max_length but 1 * x != x
x=Vector2(0.0, 7.1e62), max_length=7.1e62
x=Vector2(0.0, 7.1e62), max_length=7.1e62,
)
def test_truncate_equivalent_to_scale(x: Vector2, max_length: float):
"""Vector2.scale_to and truncate are equivalent when max_length <= x.length"""
Expand Down

0 comments on commit f7429e5

Please sign in to comment.