Skip to content

Commit c8ede38

Browse files
committed
Run black on existing entity_instance
1 parent 704e27e commit c8ede38

2 files changed

Lines changed: 26 additions & 62 deletions

File tree

src/ifcopenshell-python/docs/ifcconvert.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ table below.
2323
| .ifc | .ifcJSON | Ifc2JSON_ |
2424
+-------------------------+-------------------------+----------------------+
2525
| .ifc | .ifc | IfcPatch_ |
26-
| | (IFC2X3, IFC4, IFC4X3) | |
26+
| | (IFC2X3, IFC4, IFC4X3), | |
27+
| | SQLite, MySQL | |
2728
+-------------------------+-------------------------+----------------------+
2829
| .ifc | .json (Code_Aster), | Ifc2CA_ |
2930
| | .comm (Code_Aster) | |
@@ -33,7 +34,8 @@ table below.
3334
+-------------------------+-------------------------+----------------------+
3435
| .ifc | .csv, .ods, .xlsx | Ifc5D_ |
3536
+-------------------------+-------------------------+----------------------+
36-
| .ifc | .csv, .ods, .xlsx | IfcCSV_ |
37+
| .ifc | .csv, .ods, .xlsx, | IfcCSV_ |
38+
| | Pandas DataFrame | |
3739
+-------------------------+-------------------------+----------------------+
3840
| .csv | .ifc | Ifc5D_ |
3941
+-------------------------+-------------------------+----------------------+

src/ifcopenshell-python/ifcopenshell/entity_instance.py

Lines changed: 22 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
def set_derived_attribute(*args):
4141
raise TypeError("Unable to set derived attribute")
4242

43-
43+
4444
def set_unsupported_attribute(*args):
4545
raise TypeError("This is an unsupported attribute type")
4646

@@ -83,8 +83,7 @@ def register_schema_attributes(schema):
8383
functions = [
8484
set_derived_attribute
8585
if mname == "setArgumentAsDerived"
86-
else
87-
set_unsupported_attribute
86+
else set_unsupported_attribute
8887
if mname == "setArgumentAsUnknown"
8988
else getattr(ifcopenshell_wrapper.entity_instance, mname)
9089
for mname in fn_names
@@ -139,18 +138,12 @@ def __getattr__(self, name):
139138
idx = self.wrapped_data.get_argument_index(name)
140139
if _method_dict[self.is_a(True)][idx] != set_derived_attribute:
141140
# A bit ugly, but we fall through to derived attribute handling below
142-
return entity_instance.wrap_value(
143-
self.wrapped_data.get_argument(idx), self.wrapped_data.file
144-
)
141+
return entity_instance.wrap_value(self.wrapped_data.get_argument(idx), self.wrapped_data.file)
145142
elif attr_cat == INVERSE:
146-
vs = entity_instance.wrap_value(
147-
self.wrapped_data.get_inverse(name), self.wrapped_data.file
148-
)
143+
vs = entity_instance.wrap_value(self.wrapped_data.get_inverse(name), self.wrapped_data.file)
149144
if settings.unpack_non_aggregate_inverses:
150145
schema_name = self.wrapped_data.is_a(True).split(".")[0]
151-
ent = ifcopenshell_wrapper.schema_by_name(schema_name).declaration_by_name(
152-
self.is_a()
153-
)
146+
ent = ifcopenshell_wrapper.schema_by_name(schema_name).declaration_by_name(self.is_a())
154147
inv = [i for i in ent.all_inverse_attributes() if i.name() == name][0]
155148
if (inv.bound1(), inv.bound2()) == (-1, -1):
156149
if vs:
@@ -164,9 +157,7 @@ def __getattr__(self, name):
164157
rules = importlib.import_module(f"ifcopenshell.express.rules.{schema_name}")
165158

166159
def yield_supertypes():
167-
decl = ifcopenshell_wrapper.schema_by_name(schema_name).declaration_by_name(
168-
self.is_a()
169-
)
160+
decl = ifcopenshell_wrapper.schema_by_name(schema_name).declaration_by_name(self.is_a())
170161
while decl:
171162
yield decl.name()
172163
decl = decl.supertype()
@@ -178,8 +169,7 @@ def yield_supertypes():
178169

179170
if attr_cat != FORWARD:
180171
raise AttributeError(
181-
"entity instance of type '%s' has no attribute '%s'"
182-
% (self.wrapped_data.is_a(True), name)
172+
"entity instance of type '%s' has no attribute '%s'" % (self.wrapped_data.is_a(True), name)
183173
)
184174

185175
@staticmethod
@@ -218,11 +208,7 @@ def attribute_type(self, attr):
218208
:type attr: int
219209
:rtype: string
220210
"""
221-
attr_idx = (
222-
attr
223-
if isinstance(attr, numbers.Integral)
224-
else self.wrapped_data.get_argument_index(attr)
225-
)
211+
attr_idx = attr if isinstance(attr, numbers.Integral) else self.wrapped_data.get_argument_index(attr)
226212
return self.wrapped_data.get_argument_type(attr_idx)
227213

228214
def attribute_name(self, attr_idx):
@@ -240,33 +226,23 @@ def __setattr__(self, key, value):
240226

241227
def __getitem__(self, key):
242228
if key < 0 or key >= len(self):
243-
raise IndexError(
244-
"Attribute index {} out of range for instance of type {}".format(
245-
key, self.is_a()
246-
)
247-
)
248-
return entity_instance.wrap_value(
249-
self.wrapped_data.get_argument(key), self.wrapped_data.file
250-
)
229+
raise IndexError("Attribute index {} out of range for instance of type {}".format(key, self.is_a()))
230+
return entity_instance.wrap_value(self.wrapped_data.get_argument(key), self.wrapped_data.file)
251231

252232
def __setitem__(self, idx, value):
253233
if self.wrapped_data.file and self.wrapped_data.file.transaction:
254234
self.wrapped_data.file.transaction.store_edit(self, idx, value)
255235

256236
if self.method_list is None:
257-
super(entity_instance, self).__setattr__(
258-
"method_list", _method_dict[self.is_a(True)]
259-
)
237+
super(entity_instance, self).__setattr__("method_list", _method_dict[self.is_a(True)])
260238

261239
method = self.method_list[idx]
262240

263241
if value is None:
264242
if method is not set_derived_attribute:
265243
self.wrapped_data.setArgumentAsNull(idx)
266244
else:
267-
self.method_list[idx](
268-
self.wrapped_data, idx, entity_instance.unwrap_value(value)
269-
)
245+
self.method_list[idx](self.wrapped_data, idx, entity_instance.unwrap_value(value))
270246

271247
return value
272248

@@ -323,9 +299,9 @@ def __eq__(self, other):
323299
elif None in (self.wrapped_data.file, other.wrapped_data.file):
324300
# when not added to a file, we can only compare attribute values
325301
# and we need this for where rule evaluation
326-
return self.get_info(
302+
return self.get_info(recursive=True, include_identifier=False) == other.get_info(
327303
recursive=True, include_identifier=False
328-
) == other.get_info(recursive=True, include_identifier=False)
304+
)
329305
else:
330306
# Proper entity instances have a stable identity by means of the numeric
331307
# step id. Selected type instances (such as IfcPropertySingleValue.NominalValue
@@ -346,9 +322,7 @@ def is_entity(self):
346322
bool: True if the instance is an entity
347323
"""
348324
schema_name = self.wrapped_data.is_a(True).split(".")[0]
349-
decl = ifcopenshell_wrapper.schema_by_name(schema_name).declaration_by_name(
350-
self.is_a()
351-
)
325+
decl = ifcopenshell_wrapper.schema_by_name(schema_name).declaration_by_name(self.is_a())
352326
return isinstance(decl, ifcopenshell_wrapper.entity)
353327

354328
def compare(self, other, op, reverse=False):
@@ -436,9 +410,7 @@ def __dir__(self):
436410
)
437411
)
438412

439-
def get_info(
440-
self, include_identifier=True, recursive=False, return_type=dict, ignore=(), scalar_only=False
441-
):
413+
def get_info(self, include_identifier=True, recursive=False, return_type=dict, ignore=(), scalar_only=False):
442414
"""Return a dictionary of the entity_instance's properties (Python and IFC) and their values.
443415
444416
:param include_identifier: Whether or not to include the STEP numerical identifier
@@ -472,18 +444,14 @@ def _():
472444
yield "id", self.id()
473445
yield "type", self.is_a()
474446
except BaseException:
475-
logging.exception(
476-
"unhandled exception while getting id / type info on {}".format(
477-
self
478-
)
479-
)
447+
logging.exception("unhandled exception while getting id / type info on {}".format(self))
480448
for i in range(len(self)):
481449
try:
482450
if self.wrapped_data.get_attribute_names()[i] in ignore:
483451
continue
484452
attr_value = self[i]
485453

486-
to_include = {'v': True}
454+
to_include = {"v": True}
487455

488456
if recursive or scalar_only:
489457

@@ -500,29 +468,23 @@ def get_info_(inst):
500468
)
501469

502470
def do_ignore(inst):
503-
to_include['v'] = False
471+
to_include["v"] = False
504472
return None
505473

506474
attr_value = entity_instance.walk(
507475
is_instance, get_info_ if recursive else do_ignore, attr_value
508476
)
509477

510-
if to_include['v']:
478+
if to_include["v"]:
511479
yield self.attribute_name(i), attr_value
512480
except BaseException:
513-
logging.exception(
514-
"unhandled exception occurred setting attribute name for {}".format(
515-
self
516-
)
517-
)
481+
logging.exception("unhandled exception occurred setting attribute name for {}".format(self))
518482

519483
return return_type(_())
520484

521485
__dict__ = property(get_info)
522486

523-
def get_info_2(
524-
self, include_identifier=True, recursive=False, return_type=dict, ignore=()
525-
):
487+
def get_info_2(self, include_identifier=True, recursive=False, return_type=dict, ignore=()):
526488
assert include_identifier
527489
assert recursive
528490
assert return_type is dict

0 commit comments

Comments
 (0)