Skip to content

Commit

Permalink
Fix pylint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
John Eslick committed Jul 27, 2023
1 parent a22b478 commit e7fcc7e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
38 changes: 24 additions & 14 deletions idaes/core/base/property_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,16 @@ def __init__(
if doc is None:
doc = name

super().__setattr__("_name", name)
super().__setattr__("_doc", doc)
self._name = name
self._doc = doc

# TODO: Validate units are from UnitSet or dimensionless - needs deprecation
super().__setattr__("_units", units)
self._units = units

# Record indices - needed for building instance specific cases
super().__setattr__("_indices", indices)
self._indices = indices

self._lock_setattr = True

# Create entries for indexed sub-properties
if indices is None or indices is False:
Expand All @@ -311,7 +313,11 @@ def __repr__(self):
return f"{self._doc} ({self._units})"

def __setattr__(self, key, value):
raise TypeError("Property metadata does not support assignment.")
try:
assert self._lock_setattr == True
raise TypeError("Property metadata does not support assignment.")
except (AssertionError, AttributeError):
super().__setattr__(key, value)

@property
def name(self):
Expand Down Expand Up @@ -342,10 +348,10 @@ class PropertySetBase:
_defined_indices = ["comp", "phase", "phase_comp"]

def __init__(self, parent):
super().__setattr__("_parent_block", parent)
super().__setattr__("_defined_properties", [])
super().__setattr__("_defined_indices", copy(self.__class__._defined_indices))

self._parent_block = parent
self._defined_properties = []
self._defined_indices = copy(self.__class__._defined_indices)
self._lock_setattr = True
# Find standard properties defined in class and create instance versions
for i in dir(self.__class__):
if not i.startswith("_"):
Expand All @@ -364,9 +370,13 @@ def __init__(self, parent):
)

def __setattr__(self, key, value):
raise TypeError(
"PropertySets do not support direct assignment. Please use define_property"
)
try:
assert self._lock_setattr == True
raise TypeError(
"PropertySets do not support direct assignment. Please use define_property"
)
except (AssertionError, AttributeError):
super().__setattr__(key, value)

def __getitem__(self, key: str):
n, i = self.get_name_and_index(key)
Expand Down Expand Up @@ -576,7 +586,7 @@ def get_name_and_index(self, property_name: str):
"""
root_name = None
index_name = None
_defined_indices = {"phase_comp" "phase" "comp"} | set(self._defined_indices)
_defined_indices = {"phase_comp", "phase", "comp"} | set(self._defined_indices)

_defined_indices = list(reversed(sorted(_defined_indices, key=len)))

Expand All @@ -591,7 +601,7 @@ def get_name_and_index(self, property_name: str):
index_name = i
break

if root_name not in self._defined_properties:
if root_name is None or root_name not in self._defined_properties:
raise ValueError(
f"Unhandled property: {property_name}. This is mostly likely due to"
" the property not being defined in this PropertySet."
Expand Down
6 changes: 3 additions & 3 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[pytest]
addopts = --pyargs idaes
--durations=100
-W ignore
#addopts = --pyargs idaes
# --durations=100
# -W ignore
log_file = pytest.log
log_file_date_format = %Y-%m-%dT%H:%M:%S
log_file_format = %(asctime)s %(levelname)-7s <%(filename)s:%(lineno)d> %(message)s
Expand Down

0 comments on commit e7fcc7e

Please sign in to comment.