Skip to content

Commit 1821c7f

Browse files
committed
Put typing imports in TYPE_CHECKING block for performance
1 parent ad11b9f commit 1821c7f

File tree

13 files changed

+70
-31
lines changed

13 files changed

+70
-31
lines changed

.coveragerc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ exclude_lines =
99
@(abc\.)?abstractmethod
1010
if __name__ == .__main__.:
1111
raise NotImplemented
12+
if TYPE_CHECKING:

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ lint.select = [
104104
"PTH", # flake8-use-pathlib
105105
"RUF", # ruff-specific rules
106106
"SIM", # flake8-simplify
107+
"TC", # flake8-type-checking (performance improvements)
107108
"TRY", # tryceratops
108109
"UP", # pyupgrade
109110
"W", # pycodestyle warning

src/data_morph/bounds/bounding_box.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
from __future__ import annotations
44

5-
from collections.abc import Iterable
6-
from numbers import Number
5+
from typing import TYPE_CHECKING
76

87
from ._utils import _validate_2d
98
from .interval import Interval
109

10+
if TYPE_CHECKING:
11+
from collections.abc import Iterable
12+
from numbers import Number
13+
1114

1215
class BoundingBox:
1316
"""

src/data_morph/cli.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44

55
import argparse
66
import sys
7-
from collections.abc import Sequence
7+
from typing import TYPE_CHECKING
88

99
from . import __version__
1010
from .data.loader import DataLoader
1111
from .morpher import DataMorpher
1212
from .shapes.factory import ShapeFactory
1313

14+
if TYPE_CHECKING:
15+
from collections.abc import Sequence
16+
1417
ARG_DEFAULTS = {
1518
'output_dir': 'morphed_data',
1619
'decimals': 2,

src/data_morph/data/dataset.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
from __future__ import annotations
44

55
from numbers import Number
6+
from typing import TYPE_CHECKING
67

78
import matplotlib.pyplot as plt
8-
import pandas as pd
9-
from matplotlib.axes import Axes
109

1110
from ..bounds.bounding_box import BoundingBox
1211
from ..bounds.interval import Interval
1312
from ..plotting.style import plot_with_custom_style
1413

14+
if TYPE_CHECKING:
15+
import pandas as pd
16+
from matplotlib.axes import Axes
17+
1518

1619
class Dataset:
1720
"""

src/data_morph/data/loader.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@
44

55
from importlib.resources import files
66
from itertools import zip_longest
7-
from numbers import Number
87
from pathlib import Path
9-
from typing import ClassVar
8+
from typing import TYPE_CHECKING, ClassVar
109

1110
import matplotlib.pyplot as plt
1211
import numpy as np
1312
import pandas as pd
14-
from matplotlib.axes import Axes
1513

1614
from .. import MAIN_DIR
1715
from ..plotting.style import plot_with_custom_style
1816
from .dataset import Dataset
1917

18+
if TYPE_CHECKING:
19+
from numbers import Number
20+
21+
from matplotlib.axes import Axes
22+
2023

2124
class DataLoader:
2225
"""

src/data_morph/morpher.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
from functools import partial
66
from numbers import Number
77
from pathlib import Path
8+
from typing import TYPE_CHECKING
89

910
import numpy as np
10-
import pandas as pd
1111
import tqdm
1212

13-
from .bounds.bounding_box import BoundingBox
14-
from .data.dataset import Dataset
1513
from .data.stats import get_values
1614
from .plotting.animation import (
1715
ease_in_out_quadratic,
@@ -22,7 +20,13 @@
2220
stitch_gif_animation,
2321
)
2422
from .plotting.static import plot
25-
from .shapes.bases.shape import Shape
23+
24+
if TYPE_CHECKING:
25+
import pandas as pd
26+
27+
from .bounds.bounding_box import BoundingBox
28+
from .data.dataset import Dataset
29+
from .shapes.bases.shape import Shape
2630

2731

2832
class DataMorpher:

src/data_morph/plotting/animation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
import math
66
from functools import wraps
77
from pathlib import Path
8-
from typing import Callable
8+
from typing import TYPE_CHECKING, Callable
99

1010
from PIL import Image
1111

12-
from ..shapes.bases.shape import Shape
12+
if TYPE_CHECKING:
13+
from ..shapes.bases.shape import Shape
1314

1415

1516
def stitch_gif_animation(

src/data_morph/plotting/static.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,24 @@
22

33
from __future__ import annotations
44

5-
from collections.abc import Iterable
65
from functools import partial
7-
from numbers import Number
86
from pathlib import Path
9-
from typing import Any
7+
from typing import TYPE_CHECKING, Any
108

119
import matplotlib.pyplot as plt
1210
import numpy as np
13-
import pandas as pd
14-
from matplotlib.axes import Axes
1511
from matplotlib.ticker import EngFormatter
1612

1713
from ..data.stats import get_values
1814
from .style import plot_with_custom_style
1915

16+
if TYPE_CHECKING:
17+
from collections.abc import Iterable
18+
from numbers import Number
19+
20+
import pandas as pd
21+
from matplotlib.axes import Axes
22+
2023

2124
@plot_with_custom_style
2225
def plot(

src/data_morph/shapes/bases/line_collection.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22

33
from __future__ import annotations
44

5-
from collections.abc import Iterable
6-
from numbers import Number
5+
from typing import TYPE_CHECKING
76

87
import matplotlib.pyplot as plt
98
import numpy as np
10-
from matplotlib.axes import Axes
119

1210
from ...plotting.style import plot_with_custom_style
1311
from .shape import Shape
1412

13+
if TYPE_CHECKING:
14+
from collections.abc import Iterable
15+
from numbers import Number
16+
17+
from matplotlib.axes import Axes
18+
1519

1620
class LineCollection(Shape):
1721
"""

0 commit comments

Comments
 (0)