Skip to content

Commit bc420cd

Browse files
committed
use _attributes and ignore warnings about private stuff
1 parent 8530bb6 commit bc420cd

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

src/fuzzylogic/classes.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class Domain:
6868
in a subclass to enable concurrent evaluation for performance improvement.
6969
"""
7070

71-
__slots__ = ["name", "low", "high", "res", "_sets"]
71+
__slots__ = ["_name", "_low", "_high", "_res", "_sets"]
7272

7373
def __init__(
7474
self,
@@ -83,15 +83,15 @@ def __init__(
8383
assert res > 0, "resolution can't be negative or zero"
8484
assert isinstance(name, str), "Name must be a string."
8585
assert str.isidentifier(name), "Name must be a valid identifier."
86-
self.name = name
87-
self.high = high
88-
self.low = low
89-
self.res = res
86+
self._name = name
87+
self._high = high
88+
self._low = low
89+
self._res = res
9090
self._sets = {} if sets is None else sets # Name: Set(Function())
9191

9292
def __call__(self, x: float) -> dict[str, float]:
9393
"""Pass a value to all sets of the domain and return a dict with results."""
94-
if not (self.low <= x <= self.high):
94+
if not (self._low <= x <= self._high):
9595
raise FuzzyWarning(f"{x} is outside of domain!")
9696
return {name: s.func(x) for name, s in self._sets.items()}
9797

@@ -101,21 +101,21 @@ def __len__(self) -> int:
101101

102102
def __str__(self) -> str:
103103
"""Return a string to print()."""
104-
return self.name
104+
return self._name
105105

106106
def __repr__(self) -> str:
107107
"""Return a string so that eval(repr(Domain)) == Domain."""
108-
return f"Domain('{self.name}', {self.low}, {self.high}, res={self.res}, sets={self._sets})"
108+
return f"Domain('{self._name}', {self._low}, {self._high}, res={self._res}, sets={self._sets})"
109109

110110
def __eq__(self, other: object) -> bool:
111111
"""Test equality of two domains."""
112112
if not isinstance(other, Domain):
113113
return False
114114
return all([
115-
self.name == other.name,
116-
self.low == other.low,
117-
self.high == other.high,
118-
self.res == other.res,
115+
self._name == other._name,
116+
self._low == other._low,
117+
self._high == other._high,
118+
self._res == other._res,
119119
self._sets == other._sets,
120120
])
121121

@@ -161,10 +161,10 @@ def range(self) -> Array:
161161
162162
High upper bound is INCLUDED unlike range.
163163
"""
164-
if int(self.res) == self.res:
165-
return np.arange(self.low, self.high + self.res, int(self.res))
164+
if int(self._res) == self._res:
165+
return np.arange(self._low, self._high + self._res, int(self._res))
166166
else:
167-
return np.linspace(self.low, self.high, int((self.high - self.low) / self.res) + 1)
167+
return np.linspace(self._low, self._high, int((self._high - self._low) / self._res) + 1)
168168

169169
def min(self, x: float) -> float:
170170
"""Standard way to get the min over all membership funcs.
@@ -428,13 +428,13 @@ def __repr__(self) -> str:
428428
# print(x)
429429

430430
if self.domain is not None:
431-
return f"{self.domain.name}.{self.name}"
431+
return f"{self.domain._name}.{self.name}" # type: ignore
432432
return f"Set({__name__}({self.func.__qualname__})"
433433

434434
def __str__(self) -> str:
435435
"""Return a string for print()."""
436436
if self.domain is not None:
437-
return f"{self.domain.name}.{self.name}"
437+
return f"{self.domain._name}.{self.name}" # type: ignore
438438
return f"dangling Set({self.func.__name__}"
439439

440440
def normalized(self) -> Set:
@@ -511,9 +511,9 @@ def __call__(self, values: dict[Domain, float | int], method: str = "cog") -> fl
511511
sum_weighted_cogs += then_set.center_of_gravity() * weight
512512
sum_weights += weight
513513
index = sum_weighted_cogs / sum_weights
514-
return (target_domain.high - target_domain.low) / len(
514+
return (target_domain._high - target_domain._low) / len( # type: ignore
515515
target_domain.range
516-
) * index + target_domain.low
516+
) * index + target_domain._low # type: ignore
517517
case "centroid": # centroid == center of mass == center of gravity for simple solids
518518
raise NotImplementedError("actually the same as 'cog' if densities are uniform.")
519519
case "bisector":

src/fuzzylogic/rules.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ def weighted_sum(*, weights: dict[str, float], target_d: Domain) -> Callable[[di
7878
"""
7979
assert sum(weights.values()) == 1, breakpoint()
8080

81-
rsc = rescale(target_d.low, target_d.high)
81+
rsc = rescale(target_d._low, target_d._high) # type: ignore
8282

8383
def f(memberships: dict[str, float]) -> float:
8484
result = sum(r * weights[n] for n, r in memberships.items())
85-
return round_partial(rsc(result), target_d.res)
85+
return round_partial(rsc(result), target_d._res) # type: ignore
8686

8787
return f

0 commit comments

Comments
 (0)