Skip to content

Commit

Permalink
Merge pull request #4974 from neutrinoceros/rfc/enable_flake8-type-ch…
Browse files Browse the repository at this point in the history
…ecking_ruleset

RFC: enable `flake8-type-checking` ruleset
  • Loading branch information
neutrinoceros authored Sep 14, 2024
2 parents e22ab1f + 7c03a6d commit 69c27de
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ select = [
"C4", # flake8-comprehensions
"B", # flake8-bugbear
"G", # flake8-logging-format
"TCH", # flake8-type-checking
"YTT", # flake8-2020
"UP", # pyupgrade
"I", # isort
Expand Down
6 changes: 4 additions & 2 deletions yt/data_objects/static_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
from functools import cached_property
from importlib.util import find_spec
from stat import ST_CTIME
from typing import Any, Literal, Optional, Union
from typing import TYPE_CHECKING, Any, Literal, Optional, Union

import numpy as np
import unyt as un
from more_itertools import unzip
from sympy import Symbol
from unyt import Unit, UnitSystem, unyt_quantity
from unyt.exceptions import UnitConversionError, UnitParseError

Expand Down Expand Up @@ -75,6 +74,9 @@
from yt.utilities.parallel_tools.parallel_analysis_interface import parallel_root_only
from yt.utilities.parameter_file_storage import NoParameterShelf, ParameterFileStore

if TYPE_CHECKING:
from sympy import Symbol

if sys.version_info >= (3, 11):
from typing import assert_never
else:
Expand Down
6 changes: 4 additions & 2 deletions yt/frontends/ramses/io.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
from collections import defaultdict
from functools import lru_cache
from typing import Union
from typing import TYPE_CHECKING, Union

import numpy as np

Expand All @@ -17,6 +16,9 @@
from yt.utilities.logger import ytLogger as mylog
from yt.utilities.physical_ratios import cm_per_km, cm_per_mpc

if TYPE_CHECKING:
import os


def convert_ramses_ages(ds, conformal_ages):
issue_deprecation_warning(
Expand Down
2 changes: 1 addition & 1 deletion yt/visualization/fixed_resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def __init__(
# the filter methods for the present class are defined only when
# fixed_resolution_filters is imported, so we need to guarantee
# that it happens no later than instantiation
from yt.visualization.fixed_resolution_filters import (
from yt.visualization.fixed_resolution_filters import ( # noqa
FixedResolutionBufferFilter,
)

Expand Down
6 changes: 4 additions & 2 deletions yt/visualization/plot_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
from collections import defaultdict
from numbers import Number
from typing import Optional, Union
from typing import TYPE_CHECKING, Optional, Union

import matplotlib
import numpy as np
Expand Down Expand Up @@ -55,6 +55,9 @@
invalidate_plot,
)

if TYPE_CHECKING:
from yt.visualization.plot_modifications import PlotCallback

if sys.version_info < (3, 10):
from yt._maintenance.backports import zip

Expand Down Expand Up @@ -866,7 +869,6 @@ def __init__(self, *args, **kwargs) -> None:
# the filter methods for the present class are defined only when
# fixed_resolution_filters is imported, so we need to guarantee
# that it happens no later than instantiation
from yt.visualization.plot_modifications import PlotCallback

self._callbacks: list[PlotCallback] = []

Expand Down
8 changes: 6 additions & 2 deletions yt/visualization/profile_plotter.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import base64
import os
from collections.abc import Iterable
from functools import wraps
from typing import Any, Optional, Union
from typing import TYPE_CHECKING, Any, Optional, Union

import matplotlib
import numpy as np
Expand All @@ -28,6 +27,11 @@
validate_plot,
)

if TYPE_CHECKING:
from collections.abc import Iterable

from yt._typing import FieldKey


def invalidate_profile(f):
@wraps(f)
Expand Down

0 comments on commit 69c27de

Please sign in to comment.