Skip to content

Commit

Permalink
resolve all complains from current ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
arogozhnikov committed Apr 27, 2024
1 parent 16d4ce5 commit 19b158c
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 16 deletions.
3 changes: 2 additions & 1 deletion docs/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from PIL.Image import fromarray
from IPython import get_ipython
from IPython.display import display_html


def display_np_arrays_as_images():
Expand All @@ -23,7 +24,7 @@ def np_to_text(obj, p, cycle):
get_ipython().display_formatter.formatters['text/plain'].for_type(np.ndarray, np_to_text)


from IPython.display import display_html


_style_inline = """<style>
.einops-answer {
Expand Down
5 changes: 4 additions & 1 deletion einops/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# imports can use EinopsError class
# ruff: noqa: E402

__author__ = 'Alex Rogozhnikov'
__version__ = '0.7.0'

Expand All @@ -11,5 +14,5 @@ class EinopsError(RuntimeError):
'pack', 'unpack',
'parse_shape', 'asnumpy', 'EinopsError']

from .einops import rearrange, reduce, repeat, einsum, parse_shape, asnumpy
from .einops import rearrange, reduce, repeat, einsum, parse_shape, asnumpy
from .packing import pack, unpack
2 changes: 1 addition & 1 deletion einops/_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def shape(self, x):
try:
hash(shape)
return shape
except:
except BaseException:
# unhashable symbols in shape. Wrap tuple to be hashable.
return HashableTuple(shape)

Expand Down
2 changes: 1 addition & 1 deletion einops/einops.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

if typing.TYPE_CHECKING:
# for docstrings in pycharm
import numpy as np
import numpy as np # noqa E401

from . import EinopsError
from ._backends import get_backend
Expand Down
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ filterwarnings = [
"ignore:Call to deprecated create function OneofDescriptor",
]

[tool.black]
line-length = 120
target-version = ['py311']


[tool.ruff]
line-length = 120
target-version = 'py311'
4 changes: 2 additions & 2 deletions tests/test_einsum.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import Any, Callable
from venv import create
from . import collect_test_backends
from einops.einops import _compactify_pattern_for_einsum, einsum, EinopsError
import numpy as np
Expand Down Expand Up @@ -267,7 +266,8 @@ def test_functional_errors():
# during the pattern creation.

rstate = np.random.RandomState(0)
create_tensor = lambda *shape: rstate.uniform(size=shape).astype('float32')
def create_tensor(*shape):
return rstate.uniform(size=shape).astype('float32')

# raise NotImplementedError("Singleton () axes are not yet supported in einsum.")
with pytest.raises(NotImplementedError, match="^Singleton"):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def unet_like_1d(x, usual_convolution):
return x

# mock for convolution (works for all backends)
convolve_mock = lambda x: x
def convolve_mock(x): return x

tests = [test1, test2, test3, test4, test5, test6, test7, test8, test9, test10, test11,
lambda x: shufflenet(x, convolve=convolve_mock, c1=4, c2=5),
Expand Down
6 changes: 3 additions & 3 deletions tests/test_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_rearrange_imperative():
for shape in wrong_shapes:
try:
layer(backend.from_numpy(numpy.zeros(shape, dtype="float32")))
except:
except BaseException:
pass
else:
raise AssertionError("Failure expected")
Expand Down Expand Up @@ -119,7 +119,7 @@ def test_reduce_imperative():
for shape in wrong_shapes:
try:
layer(backend.from_numpy(numpy.zeros(shape, dtype="float32")))
except:
except BaseException:
pass
else:
raise AssertionError("Failure expected")
Expand Down Expand Up @@ -359,7 +359,7 @@ def __call__(self, x):
model = NN()
fixed_input = jnp.ones([10, 2 * 2, 3 * 3, 4])
params = model.init(jax.random.PRNGKey(0), fixed_input)
eval_at_point = lambda params: jnp.linalg.norm(model.apply(params, fixed_input))
def eval_at_point(params): return jnp.linalg.norm(model.apply(params, fixed_input))

vandg = jax.value_and_grad(eval_at_point)
value0 = eval_at_point(params)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from io import StringIO

from tests import parse_backends_to_test, is_backend_tested
from tests import is_backend_tested

__author__ = "Alex Rogozhnikov"

Expand Down
2 changes: 1 addition & 1 deletion tests/test_packing.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def unpack_and_pack_against_numpy(x, ps, pattern: str):
unpacked_np = unpack(x_np, ps, pattern)
packed_np, ps3 = pack(unpacked_np, pattern=pattern)

assert type(capturer_numpy.exception) == type(capturer_backend.exception)
assert type(capturer_numpy.exception) == type(capturer_backend.exception) # noqa E721
if capturer_numpy.exception is not None:
# both failed
return
Expand Down

0 comments on commit 19b158c

Please sign in to comment.