Skip to content

Commit e66d28c

Browse files
committed
Updated Spheres to use args_checked
1 parent 1123697 commit e66d28c

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

montepy/surfaces/general_sphere.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Copyright 2026, Battelle Energy Alliance, LLC All Rights Reserved.
2+
from __future__ import annotations
3+
4+
import montepy
25
from .surface_type import SurfaceType
36
from .surface import Surface, InitInput
47
from montepy.exceptions import *
58
from montepy.utilities import *
6-
7-
from numbers import Real
8-
from typing import Union
9+
import montepy.types as ty
910

1011

1112
def _enforce_positive_radius(self, value):
@@ -26,10 +27,12 @@ class GeneralSphere(Surface):
2627
The number to set for this object.
2728
"""
2829

30+
@args_checked
2931
def __init__(
3032
self,
3133
input: InitInput = None,
32-
number: int = None,
34+
number: ty.PositiveInt = None,
35+
surface_type: SurfaceType | str = None,
3336
):
3437
self._coordinates = [
3538
self._generate_default_node(float, None),
@@ -72,14 +75,10 @@ def coordinates(self):
7275
return tuple(c.value for c in self._coordinates)
7376

7477
@coordinates.setter
75-
def coordinates(self, coordinates):
76-
if not isinstance(coordinates, (list, tuple)):
77-
raise TypeError("coordinates must be a list")
78+
@args_checked
79+
def coordinates(self, coordinates: ty.Iterable[ty.Real]):
7880
if len(coordinates) != 3:
7981
raise ValueError("coordinates must have exactly three elements")
80-
for val in coordinates:
81-
if not isinstance(val, Real):
82-
raise TypeError(f"Coordinate must be a number. {val} given.")
8382
for i, val in enumerate(coordinates):
8483
self._coordinates[i].value = val
8584

@@ -90,6 +89,9 @@ def validate(self):
9089
if any({c is None for c in self.coordinates}):
9190
raise IllegalState(f"Surface: {self.number} does not have coordinates set.")
9291

93-
def find_duplicate_surfaces(self, surfaces, tolerance): # pragma: no cover
92+
@args_checked
93+
def find_duplicate_surfaces(
94+
self, surfaces: montepy.Surfaces, tolerance: ty.PositiveReal
95+
): # pragma: no cover
9496
"""Duplicate sphere finding is not yet implemented"""
9597
return []

montepy/surfaces/sphere_at_origin.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Copyright 2026, Battelle Energy Alliance, LLC All Rights Reserved.
2+
from __future__ import annotations
3+
4+
import montepy
25
from .surface_type import SurfaceType
36
from .surface import Surface, InitInput
47
from montepy.exceptions import *
@@ -25,10 +28,11 @@ class SphereAtOrigin(Surface):
2528
The number to set for this object.
2629
"""
2730

31+
@args_checked
2832
def __init__(
2933
self,
3034
input: InitInput = None,
31-
number: int = None,
35+
number: ty.PositiveInt = None,
3236
):
3337
self._location = self._generate_default_node(float, None)
3438
self._radius = self._generate_default_node(float, None)
@@ -56,6 +60,9 @@ def validate(self):
5660
if self.radius is None:
5761
raise IllegalState(f"Surface: {self.number} does not have a radius set.")
5862

59-
def find_duplicate_surfaces(self, surfaces, tolerance): # pragma: no cover
63+
@args_checked
64+
def find_duplicate_surfaces(
65+
self, surfaces: montepy.Surfaces, tolerance: ty.PositiveReal
66+
): # pragma: no cover
6067
"""Duplicate sphere finding is not yet implemented"""
6168
return []

montepy/surfaces/sphere_on_axis.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Copyright 2026, Battelle Energy Alliance, LLC All Rights Reserved.
2+
from __future__ import annotations
3+
4+
import montepy
25
from .surface_type import SurfaceType
36
from .surface import Surface, InitInput
47
from montepy.exceptions import *
58
from montepy.utilities import *
6-
7-
from typing import Union
9+
import montepy.types as ty
810

911

1012
def _enforce_positive_radius(self, value):
@@ -29,11 +31,12 @@ class SphereOnAxis(Surface):
2931

3032
COORDINATE = {SurfaceType.SX: "x", SurfaceType.SY: "y", SurfaceType.SZ: "z"}
3133

34+
@args_checked
3235
def __init__(
3336
self,
3437
input: InitInput = None,
35-
number: int = None,
36-
surface_type: Union[SurfaceType, str] = None,
38+
number: ty.PositiveInt = None,
39+
surface_type: SurfaceType | str = None,
3740
):
3841
self._location = self._generate_default_node(float, None)
3942
self._radius = self._generate_default_node(float, None)
@@ -81,6 +84,9 @@ def validate(self):
8184
if self.location is None:
8285
raise IllegalState(f"Surface: {self.number} does not have a location set.")
8386

84-
def find_duplicate_surfaces(self, surfaces, tolerance): # pragma: no cover
87+
@args_checked
88+
def find_duplicate_surfaces(
89+
self, surfaces: montepy.Surfaces, tolerance: ty.PositiveReal
90+
): # pragma: no cover
8591
"""Duplicate sphere finding is not yet implemented"""
8692
return []

0 commit comments

Comments
 (0)