Fix RUF015 (next() instead of list comprehensions[0])

https://docs.astral.sh/ruff/rules/-iterable-allocation-for-first-element/
This commit is contained in:
Andrej730
2025-06-16 12:29:41 +05:00
parent b486b32c8d
commit a12bb343ca
29 changed files with 64 additions and 61 deletions
@@ -48,14 +48,14 @@ def create_segment_representations(
representation.RepresentationIdentifier == "FootPrint" and representation.RepresentationType == "Curve2D"
):
curve = ifcopenshell.api.alignment.get_basis_curve(alignment)
nested_alignment = [
nested_alignment = next(
c for c in ifcopenshell.util.element.get_components(alignment) if c.is_a("IfcAlignmentHorizontal")
][0]
)
elif representation.RepresentationIdentifier == "Axis" and representation.RepresentationType == "Curve3D":
curve = ifcopenshell.api.alignment.get_curve(alignment)
nested_alignment = [
nested_alignment = next(
c for c in ifcopenshell.util.element.get_components(alignment) if c.is_a("IfcAlignmentVertical")
][0]
)
curve_segments = curve.Segments
segments = nested_alignment.IsNestedBy[0].RelatingObjects
+1 -1
View File
@@ -296,7 +296,7 @@ def main(
# file 2 only has the groups we are interested in.
# in fact in the approach, it's only a single group
g2 = list(yield_groups(svg2))[0]
g2 = next(yield_groups(svg2))
# These are attributes on the original group that we can use to reconstruct
# a 4x4 matrix of the projection used in the SVG generation process
@@ -37,7 +37,7 @@ class TestAddBoolean(test.bootstrap.IFC4):
booleans = ifcopenshell.api.geometry.add_boolean(self.file, first, [second])
assert len(booleans) == 1
boolean = list(booleans)[0]
boolean = booleans[0]
assert boolean.is_a("IfcBooleanResult")
assert boolean.FirstOperand == first
assert boolean.SecondOperand == second
@@ -107,16 +107,16 @@ class TestAddBoolean(test.bootstrap.IFC4):
assert len(rep.Items) == 2
assert self.file.get_total_inverses(first1) == 1
result = list(self.file.get_inverse(first1))[0]
result = next(iter(self.file.get_inverse(first1)))
assert result.FirstOperand == first1
assert result.SecondOperand == second1
result2 = list(self.file.get_inverse(result))[0]
result2 = next(iter(self.file.get_inverse(result)))
assert result2.FirstOperand == result
# Second2 is now used twice. Reusing is OK (albeit confusing), so long as things don't get recursive.
assert result2.SecondOperand == second2
assert self.file.get_total_inverses(first2) == 1
result3 = list(self.file.get_inverse(first2))[0]
result3 = next(iter(self.file.get_inverse(first2)))
assert result3.FirstOperand == first2
assert result3.SecondOperand == second2
@@ -81,8 +81,8 @@ class TestGetReferences(test.bootstrap.IFC4):
reference=reference2,
classification=classification,
)
reference1 = [r for r in self.file.by_type("IfcClassificationReference") if r.Identification == "1"][0]
reference2 = [r for r in self.file.by_type("IfcClassificationReference") if r.Identification == "2"][0]
reference1 = next(r for r in self.file.by_type("IfcClassificationReference") if r.Identification == "1")
reference2 = next(r for r in self.file.by_type("IfcClassificationReference") if r.Identification == "2")
assert subject.get_references(element_type) == set([reference2])
assert subject.get_references(element) == set([reference1])