Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import Self from fuzzylite to deal with python versions #80

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion fuzzylite/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@

from __future__ import annotations

__all__ = ["Array", "Scalar", "ScalarArray"]
__all__ = ["Array", "Scalar", "ScalarArray", "Self"]

import sys
from typing import Any, Union

import numpy as np
from numpy.typing import NDArray as Array

Scalar = Union[float, np.floating[Any], Array[np.floating[Any]]]
ScalarArray = Array[np.floating[Any]]

if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self
4 changes: 2 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def check(session: nox.Session) -> None:
def format(session: nox.Session) -> None:
"""Run code formatting."""
formatters = {
"ruff": format_ruff,
# "ruff": format_ruff,
"black": format_black,
}
posargs = list(session.posargs)
Expand Down Expand Up @@ -57,7 +57,7 @@ def format_ruff(session: nox.Session) -> None:
def lint(session: nox.Session) -> None:
"""Run static code analysis and checks format is correct."""
linters = {
"ruff": lint_ruff,
# "ruff": lint_ruff,
"black": lint_black,
"pyright": lint_pyright,
"mypy": lint_mypy,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ pyright = "^1.1.362" # Static code analysis
pytest = "^7.3.1" # Test driven development
pytest-benchmark = "^4.0.0" # Local benchmarks
pytest-codspeed = "^2.0.1" # Cloud benchmarks
ruff = "^0.4.4" # Code formatting

# Packages below are ground truth for version management. See requirements-dev.txt.
# poetry = "~=1.8.3" # Build management
Expand Down Expand Up @@ -109,6 +108,7 @@ select = [
"ISC", # flake8-implicit-str-concat
"N", # pep8 naming
"NPY", # NumPy-specific rules
"NPY201", # NumPy 2.0 specific rules
# "PD", # pandas-vet
"PLW", # warning
# "PTH", # flake8-use-pathlib
Expand Down
2 changes: 1 addition & 1 deletion tests/assert_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
from typing import Any, Generic, TypeVar

import numpy as np
from typing_extensions import Self

import fuzzylite as fl
from fuzzylite.types import Self

T = TypeVar("T")

Expand Down
3 changes: 1 addition & 2 deletions tests/test_defuzzifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
from typing import Any

import numpy as np
from typing_extensions import Self

import fuzzylite as fl
from fuzzylite.types import Scalar
from fuzzylite.types import Scalar, Self
from tests.assert_component import BaseAssert


Expand Down
2 changes: 1 addition & 1 deletion tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

import black
import numpy as np
from typing_extensions import Self

import fuzzylite as fl
from fuzzylite.examples.mamdani.simple_dimmer import SimpleDimmer
from fuzzylite.types import Self
from tests.assert_component import BaseAssert


Expand Down
2 changes: 1 addition & 1 deletion tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
)

import numpy as np
from typing_extensions import Self

import fuzzylite as fl
from fuzzylite.types import Self
from tests.assert_component import BaseAssert


Expand Down
2 changes: 1 addition & 1 deletion tests/test_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_library_exports_dir(self) -> None:
GaussianProduct Linear PiShape Ramp Rectangle SShape SemiEllipse Sigmoid SigmoidDifference
SigmoidProduct Spike Term Trapezoid Triangle ZShape

types Array Scalar ScalarArray
types Array Scalar ScalarArray Self

variable InputVariable OutputVariable Variable
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_term.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
from typing import Callable, NoReturn

import numpy as np
from typing_extensions import Self

import fuzzylite as fl
import fuzzylite.library
from fuzzylite import Scalar, inf, nan
from fuzzylite.types import Self
from tests.assert_component import BaseAssert


Expand Down
2 changes: 1 addition & 1 deletion tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
from unittest.mock import MagicMock

import numpy as np
from typing_extensions import Self

import fuzzylite as fl
from fuzzylite.types import Self
from tests.assert_component import BaseAssert

T_Variable = TypeVar("T_Variable", bound=fl.Variable)
Expand Down
Loading