Skip to content

Commit 64d91b5

Browse files
committed
fix type hints + ruff
1 parent c7e83dc commit 64d91b5

File tree

6 files changed

+19
-47
lines changed

6 files changed

+19
-47
lines changed

armi/reactor/components/component.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,7 @@ def resolveLinkedDims(self, components):
331331
f"Components cannot not have periods in their names: `{value}`"
332332
)
333333
else:
334-
raise KeyError(
335-
f"Bad component link `{dimName}` defined as `{value}` in {self}"
336-
)
334+
raise KeyError(f"Bad component link `{dimName}` defined as `{value}` in {self}")
337335

338336
def setLink(self, key, otherComp, otherCompKey):
339337
"""Set the dimension link."""
@@ -667,7 +665,7 @@ def getNumberDensity(self, nucName):
667665
"""
668666
return self.p.numberDensities.get(nucName, 0.0)
669667

670-
def getNuclideNumberDensities(self, nucNames):
668+
def getNuclideNumberDensities(self, nucNames: list[str]) -> list[float]:
671669
"""Return a list of number densities for the nuc names requested."""
672670
return [self.p.numberDensities.get(nucName, 0.0) for nucName in nucNames]
673671

@@ -831,7 +829,7 @@ def getMassEnrichment(self):
831829
except ZeroDivisionError:
832830
return 0.0
833831

834-
def getMass(self, nuclideNames=None):
832+
def getMass(self, nuclideNames: None | str | list[str] = None) -> float:
835833
r"""
836834
Determine the mass in grams of nuclide(s) and/or elements in this object.
837835

armi/reactor/composites.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
Optional,
4747
Tuple,
4848
Type,
49-
Union,
5049
)
5150

5251
import numpy as np
@@ -886,7 +885,7 @@ def getMaxArea(self):
886885
"""
887886
raise NotImplementedError()
888887

889-
def getMass(self, nuclideNames=Optional[str]) -> float:
888+
def getMass(self, nuclideNames: None | str | list[str] = None) -> float:
890889
"""
891890
Determine the mass in grams of nuclide(s) and/or elements in this object.
892891
@@ -930,7 +929,7 @@ def getMicroSuffix(self):
930929
" of composite such as Blocks or Components have the concept of micro suffixes."
931930
)
932931

933-
def _getNuclidesFromSpecifier(self, nucSpec):
932+
def _getNuclidesFromSpecifier(self, nucSpec: None | str | list[str]):
934933
"""
935934
Convert a nuclide specification to a list of valid nuclide/element keys.
936935
@@ -2175,7 +2174,7 @@ def getComponentsOfMaterial(self, material=None, materialName=None):
21752174
componentsWithThisMat.append(c)
21762175
return componentsWithThisMat
21772176

2178-
def hasComponents(self, typeSpec: Union[TypeSpec, List[TypeSpec]], exact=False):
2177+
def hasComponents(self, typeSpec: TypeSpec | List[TypeSpec], exact=False):
21792178
"""
21802179
Return true if components matching all TypeSpec exist in this object.
21812180
@@ -2214,9 +2213,7 @@ def getComponentByName(self, name: str) -> "Component":
22142213
else:
22152214
return components[0]
22162215

2217-
def getComponent(
2218-
self, typeSpec: TypeSpec, exact=False, quiet=False
2219-
) -> Optional["Component"]:
2216+
def getComponent(self, typeSpec: TypeSpec, exact=False, quiet=False) -> Optional["Component"]:
22202217
"""
22212218
Get a particular component from this object.
22222219
@@ -2253,9 +2250,7 @@ def getComponent(
22532250
)
22542251
return None
22552252
else:
2256-
raise ValueError(
2257-
f"Multiple components match in {self} match typeSpec {typeSpec}: {results}"
2258-
)
2253+
raise ValueError(f"Multiple components match in {self} match typeSpec {typeSpec}: {results}")
22592254

22602255
def getNumComponents(self, typeSpec: TypeSpec, exact=False):
22612256
"""
@@ -2670,9 +2665,7 @@ def getChildren(
26702665
def getComponents(self, typeSpec: TypeSpec = None, exact=False):
26712666
return list(self.iterComponents(typeSpec, exact))
26722667

2673-
def iterComponents(
2674-
self, typeSpec: TypeSpec = None, exact=False
2675-
) -> Iterator["Component"]:
2668+
def iterComponents(self, typeSpec: TypeSpec = None, exact=False) -> Iterator["Component"]:
26762669
"""
26772670
Return an iterator of armi.reactor.component.Component objects within this Composite.
26782671

armi/reactor/converters/axialExpansionChanger/axialExpansionChanger.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,7 @@ def _checkBlockHeight(b):
423423
3cm is a presumptive lower threshold for DIF3D
424424
"""
425425
if b.getHeight() < 3.0:
426-
runLog.debug(
427-
f"Block {b.name} ({str(b.p.flags)}) has a height less than 3.0 cm. ({b.getHeight():.12e})"
428-
)
426+
runLog.debug(f"Block {b.name} ({str(b.p.flags)}) has a height less than 3.0 cm. ({b.getHeight():.12e})")
429427

430428
if b.getHeight() < 0.0:
431-
raise ArithmeticError(
432-
f"Block {b.name} ({str(b.p.flags)}) has a negative height! ({b.getHeight():.12e})"
433-
)
429+
raise ArithmeticError(f"Block {b.name} ({str(b.p.flags)}) has a negative height! ({b.getHeight():.12e})")

armi/reactor/converters/axialExpansionChanger/expansionData.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ def setExpansionFactors(self, components: list["Component"], expFrac: list[float
117117
for exp in expFrac:
118118
if exp <= 0.0:
119119
raise RuntimeError(
120-
f"Expansion factor {exp}, L1/L0, is not physical. Expansion fractions "
121-
"should be greater than 0.0."
120+
f"Expansion factor {exp}, L1/L0, is not physical. Expansion fractions should be greater than 0.0."
122121
)
123122
for c, p in zip(components, expFrac):
124123
self._expansionFactors[c] = p

armi/reactor/converters/tests/test_assemblyAxialLinkage.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,9 @@ def test_multiIndexLocation(self):
147147
lowerFuel1, lowerFuel2 = lowerB.getComponents(Flags.FUEL)
148148
upperFuel1, _upperFuel2 = upperB.getComponents(Flags.FUEL)
149149
# same grid locs, are linked
150-
self.assertTrue(
151-
AssemblyAxialLinkage.areAxiallyLinked(lowerFuel1, upperFuel1)
152-
)
150+
self.assertTrue(AssemblyAxialLinkage.areAxiallyLinked(lowerFuel1, upperFuel1))
153151
# different grid locs, are not linked
154-
self.assertFalse(
155-
AssemblyAxialLinkage.areAxiallyLinked(lowerFuel2, upperFuel1)
156-
)
152+
self.assertFalse(AssemblyAxialLinkage.areAxiallyLinked(lowerFuel2, upperFuel1))
157153

158154

159155
class TestCheckOverlap(AxialExpansionTestBase):
@@ -249,9 +245,7 @@ def test_thinAnnularPinOverlappingWithThickAnnulus(self):
249245
self.runTest(componentTypesToTest, self.assertTrue)
250246

251247
def test_AnnularHexOverlappingThickAnnularHex(self):
252-
componentTypesToTest = {
253-
Hexagon: [{"op": 1.0, "ip": 0.8}, {"op": 1.2, "ip": 0.8}]
254-
}
248+
componentTypesToTest = {Hexagon: [{"op": 1.0, "ip": 0.8}, {"op": 1.2, "ip": 0.8}]}
255249
self.runTest(componentTypesToTest, self.assertTrue)
256250

257251

@@ -302,9 +296,7 @@ def test_multiBlock(self):
302296

303297
def test_emptyBlocks(self):
304298
"""Test even smaller edge case when no blocks are passed."""
305-
with self.assertRaisesRegex(
306-
ValueError, "No blocks passed. Cannot determine links"
307-
):
299+
with self.assertRaisesRegex(ValueError, "No blocks passed. Cannot determine links"):
308300
AssemblyAxialLinkage.getLinkedBlocks([])
309301

310302
def test_onAssembly(self):

armi/reactor/converters/tests/test_axialExpansionChanger.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -678,9 +678,7 @@ def test_updateCompTempsBy1DTempFieldValError(self):
678678
def test_updateCompTempsBy1DTempFieldError(self):
679679
tempGrid = [5.0, 15.0, 35.0]
680680
tempField = linspace(25.0, 310.0, 10)
681-
with self.assertRaisesRegex(
682-
RuntimeError, "tempGrid and tempField must have the same length."
683-
):
681+
with self.assertRaisesRegex(RuntimeError, "tempGrid and tempField must have the same length."):
684682
self.obj.expansionData.updateComponentTempsBy1DTempField(tempGrid, tempField)
685683

686684
def test_AssemblyAxialExpansionException(self):
@@ -714,9 +712,7 @@ def test_isFuelLocked(self):
714712
}
715713
shield = Circle("shield", "FakeMat", **shieldDims)
716714
bNoFuel.add(shield)
717-
with self.assertRaisesRegex(
718-
RuntimeError, f"No fuel component within {bNoFuel}!"
719-
):
715+
with self.assertRaisesRegex(RuntimeError, f"No fuel component within {bNoFuel}!"):
720716
expdata._isFuelLocked(bNoFuel)
721717

722718

@@ -966,9 +962,7 @@ def checkColdHeightBlockMass(self, bStd: HexBlock, bExp: HexBlock, nuclide: str)
966962
self.assertGreater(bExp.getMass(nuclide), bStd.getMass(nuclide))
967963

968964

969-
def checkColdBlockHeight(
970-
bStd: HexBlock, bExp: HexBlock, assertType: Callable, strForAssertion: str
971-
):
965+
def checkColdBlockHeight(bStd: HexBlock, bExp: HexBlock, assertType: Callable, strForAssertion: str):
972966
assertType(
973967
bStd.getHeight(),
974968
bExp.getHeight(),

0 commit comments

Comments
 (0)