Skip to content

Commit ccd593c

Browse files
authored
Import Self from fuzzylite to deal with python versions (#80)
* Import Self from fuzzylite to deal with python versions * Remove ruff * Black formatting
1 parent 6429702 commit ccd593c

File tree

10 files changed

+17
-12
lines changed

10 files changed

+17
-12
lines changed

fuzzylite/types.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@
1111

1212
from __future__ import annotations
1313

14-
__all__ = ["Array", "Scalar", "ScalarArray"]
14+
__all__ = ["Array", "Scalar", "ScalarArray", "Self"]
1515

16+
import sys
1617
from typing import Any, Union
1718

1819
import numpy as np
1920
from numpy.typing import NDArray as Array
2021

2122
Scalar = Union[float, np.floating[Any], Array[np.floating[Any]]]
2223
ScalarArray = Array[np.floating[Any]]
24+
25+
if sys.version_info >= (3, 11):
26+
from typing import Self
27+
else:
28+
from typing_extensions import Self

noxfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def check(session: nox.Session) -> None:
2727
def format(session: nox.Session) -> None:
2828
"""Run code formatting."""
2929
formatters = {
30-
"ruff": format_ruff,
30+
# "ruff": format_ruff,
3131
"black": format_black,
3232
}
3333
posargs = list(session.posargs)
@@ -57,7 +57,7 @@ def format_ruff(session: nox.Session) -> None:
5757
def lint(session: nox.Session) -> None:
5858
"""Run static code analysis and checks format is correct."""
5959
linters = {
60-
"ruff": lint_ruff,
60+
# "ruff": lint_ruff,
6161
"black": lint_black,
6262
"pyright": lint_pyright,
6363
"mypy": lint_mypy,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ pyright = "^1.1.362" # Static code analysis
7676
pytest = "^7.3.1" # Test driven development
7777
pytest-benchmark = "^4.0.0" # Local benchmarks
7878
pytest-codspeed = "^2.0.1" # Cloud benchmarks
79-
ruff = "^0.4.4" # Code formatting
8079

8180
# Packages below are ground truth for version management. See requirements-dev.txt.
8281
# poetry = "~=1.8.3" # Build management
@@ -109,6 +108,7 @@ select = [
109108
"ISC", # flake8-implicit-str-concat
110109
"N", # pep8 naming
111110
"NPY", # NumPy-specific rules
111+
"NPY201", # NumPy 2.0 specific rules
112112
# "PD", # pandas-vet
113113
"PLW", # warning
114114
# "PTH", # flake8-use-pathlib

tests/assert_component.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
from typing import Any, Generic, TypeVar
1616

1717
import numpy as np
18-
from typing_extensions import Self
1918

2019
import fuzzylite as fl
20+
from fuzzylite.types import Self
2121

2222
T = TypeVar("T")
2323

tests/test_defuzzifier.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
from typing import Any
1717

1818
import numpy as np
19-
from typing_extensions import Self
2019

2120
import fuzzylite as fl
22-
from fuzzylite.types import Scalar
21+
from fuzzylite.types import Scalar, Self
2322
from tests.assert_component import BaseAssert
2423

2524

tests/test_engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
import black
1818
import numpy as np
19-
from typing_extensions import Self
2019

2120
import fuzzylite as fl
2221
from fuzzylite.examples.mamdani.simple_dimmer import SimpleDimmer
22+
from fuzzylite.types import Self
2323
from tests.assert_component import BaseAssert
2424

2525

tests/test_factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
)
2121

2222
import numpy as np
23-
from typing_extensions import Self
2423

2524
import fuzzylite as fl
25+
from fuzzylite.types import Self
2626
from tests.assert_component import BaseAssert
2727

2828

tests/test_library.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def test_library_exports_dir(self) -> None:
6262
GaussianProduct Linear PiShape Ramp Rectangle SShape SemiEllipse Sigmoid SigmoidDifference
6363
SigmoidProduct Spike Term Trapezoid Triangle ZShape
6464
65-
types Array Scalar ScalarArray
65+
types Array Scalar ScalarArray Self
6666
6767
variable InputVariable OutputVariable Variable
6868
"""

tests/test_term.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
from typing import Callable, NoReturn
2020

2121
import numpy as np
22-
from typing_extensions import Self
2322

2423
import fuzzylite as fl
2524
import fuzzylite.library
2625
from fuzzylite import Scalar, inf, nan
26+
from fuzzylite.types import Self
2727
from tests.assert_component import BaseAssert
2828

2929

tests/test_variable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
from unittest.mock import MagicMock
1919

2020
import numpy as np
21-
from typing_extensions import Self
2221

2322
import fuzzylite as fl
23+
from fuzzylite.types import Self
2424
from tests.assert_component import BaseAssert
2525

2626
T_Variable = TypeVar("T_Variable", bound=fl.Variable)

0 commit comments

Comments
 (0)