-
Notifications
You must be signed in to change notification settings - Fork 2
DSL Bring Up 1 #141
DSL Bring Up 1 #141
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -398,14 +398,14 @@ def __init__( | |
self.units = units or min_unit or max_unit | ||
self.range_units = base_units(self.units) | ||
|
||
if isinstance(min, Quantity): | ||
if HasUnit.check(min): | ||
num_min = min.to_base_units().magnitude | ||
Comment on lines
+401
to
402
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can not work. HasUnit.check checks if something has an units attr, but in the following we act like the variable is a Quantity (.to_base_units) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might been a better It was to guard against this issue: #141 (comment) |
||
if not (isinstance(num_min, float) or isinstance(num_min, int)): | ||
raise ValueError("min must be a float or int quantity") | ||
else: | ||
num_min = min | ||
|
||
if isinstance(max, Quantity): | ||
if HasUnit.check(max): | ||
num_max = max.to_base_units().magnitude | ||
if not (isinstance(num_max, float) or isinstance(num_max, int)): | ||
raise ValueError("max must be a float or int quantity") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
from typing import Any | ||
|
||
from pint import Quantity as _Quantity # noqa: F401 | ||
from pint import UndefinedUnitError, Unit, UnitRegistry # noqa: F401 | ||
from pint import UndefinedUnitError, UnitRegistry # noqa: F401 | ||
from pint.util import UnitsContainer as _UnitsContainer | ||
|
||
from faebryk.libs.util import cast_assert | ||
|
@@ -14,6 +14,7 @@ | |
|
||
UnitsContainer = _UnitsContainer | str | ||
Quantity = P.Quantity | ||
Unit = P.Unit | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is different than above. The types are not the same. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, changed this because it was breaking stuff in the front-end [pseudocode] from ... import Unit, Quantity
def _get_unit(name: str) -> Unit:
return Unit(name)
assert isinstanc(10 * _get_unit("mV"), Quantity) # <-- fails ^ This (distilled down) is what'd fail in the front-end because the Quantity and Unit were from different unit registrys |
||
dimensionless = cast_assert(Unit, P.dimensionless) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -957,7 +957,7 @@ def debugging() -> bool: | |
return debugpy.is_client_connected() | ||
|
||
|
||
class FuncSet[T, H: Hashable](collections.abc.Set[T]): | ||
class FuncSet[T, H: Hashable](collections.abc.MutableSet[T]): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What you are trying to implement is a custom eq function instead of a custom hasher that is removing collisions. Then no need for the discard stuff. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was using |
||
""" | ||
A set by pre-processing the objects with the hasher function. | ||
""" | ||
|
@@ -973,6 +973,13 @@ def add(self, item: T): | |
if item not in self._deref[self._hasher(item)]: | ||
self._deref[self._hasher(item)].append(item) | ||
|
||
def discard(self, item: T): | ||
hashed = self._hasher(item) | ||
if hashed in self._deref and item in self._deref[hashed]: | ||
self._deref[hashed].remove(item) | ||
if not self._deref[hashed]: | ||
del self._deref[hashed] | ||
|
||
def __contains__(self, item: T): | ||
return item in self._deref[self._hasher(item)] | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you need this because you first make the Param then find out about its within&sofset.
Got to make sure that we take the mutable within & softset into account everywhere. Maybe limiting it with '@assert_once' might be a good idea for the moment,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that idea. It won't work for the front-end because of how overrides currently work in
ato
.Maybe this deserves another issue to improve safety around later? No one in their right mind should do this without being quite sure of what they're doing