Skip to content

Commit 26801cc

Browse files
committed
Ruff: enable TC
1 parent ff5fb71 commit 26801cc

11 files changed

Lines changed: 67 additions & 19 deletions

File tree

doc/codegen.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,27 @@ Code Generation
44
.. automodule:: sumpy.codegen
55
.. automodule:: sumpy.assignment_collection
66
.. automodule:: sumpy.cse
7+
8+
References
9+
----------
10+
11+
This is only here because Sphinx (the documentation tool) fails to resolve these
12+
references properly.
13+
14+
.. currentmodule:: lp
15+
16+
.. class:: TranslationUnit
17+
18+
See :class:`loopy.TranslationUnit`.
19+
20+
.. currentmodule:: sp
21+
22+
.. class:: Expr
23+
24+
See :class:`sympy.core.expr.Expr`.
25+
26+
.. currentmodule:: np
27+
28+
.. class:: ndarray
29+
30+
See :class:`numpy.ndarray`.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ extend-select = [
9191
"SIM", # flake8-simplify
9292
"UP", # pyupgrade
9393
"W", # pycodestyle
94+
"TC",
9495
]
9596
extend-ignore = [
9697
"C90", # McCabe complexity

sumpy/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@
2424
"""
2525

2626
import os
27-
from collections.abc import Hashable
27+
from typing import TYPE_CHECKING
2828

29-
import loopy as lp
3029
from pytools.persistent_dict import WriteOncePersistentDict
3130

3231
from sumpy.e2e import (
@@ -44,6 +43,12 @@
4443
from sumpy.version import VERSION_TEXT
4544

4645

46+
if TYPE_CHECKING:
47+
from collections.abc import Hashable
48+
49+
import loopy as lp
50+
51+
4752
__all__ = [
4853
"P2P",
4954
"E2EFromCSR",

sumpy/expansion/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,23 @@
2525

2626
import logging
2727
from abc import ABC, abstractmethod
28-
from collections.abc import Hashable, Sequence
29-
from typing import Any, ClassVar
28+
from typing import TYPE_CHECKING, Any, ClassVar
3029

31-
import loopy as lp
3230
import pymbolic.primitives as prim
3331
from pytools import memoize_method
3432

3533
import sumpy.symbolic as sym
36-
from sumpy.kernel import Kernel
3734
from sumpy.tools import add_mi
3835

3936

37+
if TYPE_CHECKING:
38+
from collections.abc import Hashable, Sequence
39+
40+
import loopy as lp
41+
42+
from sumpy.kernel import Kernel
43+
44+
4045
logger = logging.getLogger(__name__)
4146

4247

sumpy/expansion/diff_op.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
"""
2727

2828
import logging
29-
from collections.abc import Mapping, Sequence
3029
from dataclasses import dataclass
3130
from itertools import accumulate
31+
from typing import TYPE_CHECKING
3232

3333
import numpy as np
3434
import sympy as sp
@@ -41,6 +41,10 @@
4141
from sumpy.tools import add_mi
4242

4343

44+
if TYPE_CHECKING:
45+
from collections.abc import Mapping, Sequence
46+
47+
4448
logger = logging.getLogger(__name__)
4549

4650
__doc__ = """

sumpy/expansion/loopy.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"""
2525

2626
import logging
27-
from collections.abc import Sequence
27+
from typing import TYPE_CHECKING
2828

2929
import numpy as np
3030

@@ -33,11 +33,16 @@
3333

3434
import sumpy.symbolic as sym
3535
from sumpy.assignment_collection import SymbolicAssignmentCollection
36-
from sumpy.expansion import ExpansionBase
37-
from sumpy.kernel import Kernel
3836
from sumpy.tools import gather_loopy_arguments, gather_loopy_source_arguments
3937

4038

39+
if TYPE_CHECKING:
40+
from collections.abc import Sequence
41+
42+
from sumpy.expansion import ExpansionBase
43+
from sumpy.kernel import Kernel
44+
45+
4146
logger = logging.getLogger(__name__)
4247

4348

sumpy/expansion/m2l.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,8 +1076,8 @@ def loopy_translation_classes_dependent_data(tgt_expansion, src_expansion,
10761076
for i in range(len(insns)):
10771077
insn = insns[i]
10781078
if isinstance(insn, lp.Assignment) and \
1079-
cast(p.Variable, insn.assignee).name.startswith(vec_name):
1080-
idx = int(cast(p.Variable, insn.assignee).name[len(vec_name):])
1079+
cast("p.Variable", insn.assignee).name.startswith(vec_name):
1080+
idx = int(cast("p.Variable", insn.assignee).name[len(vec_name):])
10811081
insns[i] = lp.Assignment(
10821082
assignee=data[idx],
10831083
expression=insn.expression,

sumpy/kernel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from typing import TYPE_CHECKING, ClassVar
2929

3030
import numpy as np
31-
import sympy as sp
3231

3332
import loopy as lp
3433
import pymbolic.primitives as prim
@@ -42,6 +41,8 @@
4241

4342

4443
if TYPE_CHECKING:
44+
import sympy as sp
45+
4546
from sumpy.expansion.diff_op import LinearPDESystemOperator
4647

4748

sumpy/tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import numpy as np
4141

4242
import loopy as lp
43-
import pyopencl as cl
4443
from pymbolic.mapper import WalkMapper
4544
from pytools import memoize_method
4645
from pytools.tag import Tag, tag_dataclass
@@ -52,6 +51,7 @@
5251
import numpy
5352

5453
import pyopencl
54+
import pyopencl as cl
5555

5656
from sumpy.kernel import Kernel
5757

sumpy/toys.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from __future__ import annotations
22

3-
from sumpy.expansion.m2l import M2LTranslationClassFactoryBase
4-
53

64
__copyright__ = """
75
Copyright (C) 2017 Andreas Kloeckner
@@ -28,7 +26,6 @@
2826
THE SOFTWARE.
2927
"""
3028

31-
from collections.abc import Sequence
3229
from functools import partial
3330
from numbers import Number
3431
from typing import TYPE_CHECKING
@@ -39,8 +36,11 @@
3936

4037

4138
if TYPE_CHECKING:
39+
from collections.abc import Sequence
40+
4241
import pyopencl
4342

43+
from sumpy.expansion.m2l import M2LTranslationClassFactoryBase
4444
from sumpy.kernel import Kernel
4545
from sumpy.visualization import FieldPlotter
4646

0 commit comments

Comments
 (0)