Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding more type hints #250

Merged
merged 8 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ requirements:
- plotly
- brep_part_finder >=0.4.1 # [not win]
- brep_to_h5m >=0.3.1 # [not win]
- moab >=5.3.1
# - jupyter-cadquery not available on conda

test:
Expand Down
4 changes: 3 additions & 1 deletion paramak/parametric_components/blanket_cutter_parallels.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Iterable, Union

from paramak import ExtrudeStraightShape
from paramak.utils import cut_solid

Expand Down Expand Up @@ -28,7 +30,7 @@ def __init__(
gap_size: float,
height: float = 2000.0,
width: float = 2000.0,
azimuth_placement_angle=[
azimuth_placement_angle: Union[float, Iterable[float]] = [
0.0,
36.0,
72.0,
Expand Down
4 changes: 2 additions & 2 deletions paramak/parametric_components/blanket_cutters_star.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Union
from typing import Iterable, Union

from paramak import ExtrudeStraightShape

Expand All @@ -25,7 +25,7 @@ def __init__(
distance: float,
height: float = 2000.0,
width: float = 2000.0,
azimuth_placement_angle: Union[float, List[float]] = [
azimuth_placement_angle: Union[float, Iterable[float]] = [
0.0,
36.0,
72.0,
Expand Down
16 changes: 8 additions & 8 deletions paramak/parametric_components/blanket_fp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import warnings
from typing import Optional, Union
from typing import Optional, Union, Iterable

import mpmath
import numpy as np
Expand Down Expand Up @@ -47,13 +47,13 @@ def __init__(
start_angle: float,
stop_angle: float,
plasma: Optional[Union[paramak.Plasma, paramak.PlasmaBoundaries, paramak.PlasmaFromPoints]] = None,
minor_radius: Optional[float] = 150.0,
major_radius: Optional[float] = 450.0,
triangularity: Optional[float] = 0.55,
elongation: Optional[float] = 2.0,
vertical_displacement: Optional[float] = 0.0,
offset_from_plasma: Union[float, list] = 0.0,
num_points: Optional[int] = 50,
minor_radius: float = 150.0,
major_radius: float = 450.0,
triangularity: float = 0.55,
elongation: float = 2.0,
vertical_displacement: float = 0.0,
offset_from_plasma: Union[float, Iterable[float]] = 0.0,
num_points: int = 50,
allow_overlapping_shape=False,
**kwargs
):
Expand Down
14 changes: 7 additions & 7 deletions paramak/parametric_components/blanket_poloidal_segment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import warnings
from typing import Callable, List, Optional, Tuple, Union
from typing import Callable, Iterable, Optional, Tuple, Union

import numpy as np
from scipy.optimize import minimize
Expand Down Expand Up @@ -29,8 +29,8 @@ class BlanketFPPoloidalSegments(BlanketFP):

def __init__(
self,
segments_angles: Optional[List[float]] = None,
num_segments: Optional[int] = 7,
segments_angles: Optional[Iterable[float]] = None,
num_segments: int = 7,
length_limits: Optional[Tuple[Union[float, None], Union[float, None]]] = None,
nb_segments_limits: Optional[Tuple[float, float]] = None,
segments_gap: Optional[float] = 0.0,
Expand Down Expand Up @@ -173,14 +173,14 @@ def create_segment_cutters(self):
self.segments_cutters = cutting_shape


def compute_lengths_from_angles(angles: List[float], distribution: Callable):
def compute_lengths_from_angles(angles: Iterable[float], distribution: Callable):
"""Computes the length of segments between a set of points on a (x,y)
distribution.

Args:
angles (list): Contains the angles of the points (degree)
distribution (callable): function taking an angle as argument and
returning (x,y) coordinates.
angles: Contains the angles of the points (degrees)
distribution: function taking an angle as argument and returning (x,y)
coordinates.

Returns:
list: contains the lengths of the segments.
Expand Down
10 changes: 5 additions & 5 deletions paramak/parametric_components/center_column_cylinder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional, Tuple
from typing import Optional, Tuple, Union

from paramak import RotateStraightShape

Expand Down Expand Up @@ -40,7 +40,7 @@ def center_height(self):
return self._center_height

@center_height.setter
def center_height(self, value):
def center_height(self, value: Union[float, int]):
if not isinstance(value, (int, float)):
msg = f"CenterColumnShieldBlock.center_height should be a float or int. Not a {type(value)}"
raise TypeError(msg)
Expand All @@ -52,7 +52,7 @@ def height(self):
return self._height

@height.setter
def height(self, value):
def height(self, value: float):
if value is None:
raise ValueError("height of the CenterColumnShieldBlock cannot be None")
self._height = value
Expand All @@ -62,7 +62,7 @@ def inner_radius(self):
return self._inner_radius

@inner_radius.setter
def inner_radius(self, value):
def inner_radius(self, value: float):
if hasattr(self, "outer_radius"):
if value >= self.outer_radius:
msg = f"inner_radius ({value}) is larger than outer_radius " "({self.outer_radius})"
Expand All @@ -74,7 +74,7 @@ def outer_radius(self):
return self._outer_radius

@outer_radius.setter
def outer_radius(self, value):
def outer_radius(self, value: float):
if hasattr(self, "inner_radius"):
if value <= self.inner_radius:
msg = f"inner_radius ({self.inner_radius}) is larger than " "outer_radius ({value})"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,31 @@ def arc_height(self):
return self._arc_height

@arc_height.setter
def arc_height(self, arc_height):
def arc_height(self, arc_height: float):
self._arc_height = arc_height

@property
def inner_radius(self):
return self._inner_radius

@inner_radius.setter
def inner_radius(self, inner_radius):
def inner_radius(self, inner_radius: float):
self._inner_radius = inner_radius

@property
def mid_radius(self):
return self._mid_radius

@mid_radius.setter
def mid_radius(self, mid_radius):
def mid_radius(self, mid_radius: float):
self._mid_radius = mid_radius

@property
def outer_radius(self):
return self._outer_radius

@outer_radius.setter
def outer_radius(self, outer_radius):
def outer_radius(self, outer_radius: float):
self._outer_radius = outer_radius

def find_points(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,39 +48,39 @@ def height(self):
return self._height

@height.setter
def height(self, height):
def height(self, height: float):
self._height = height

@property
def arc_height(self):
return self._arc_height

@arc_height.setter
def arc_height(self, arc_height):
def arc_height(self, arc_height: float):
self._arc_height = arc_height

@property
def inner_radius(self):
return self._inner_radius

@inner_radius.setter
def inner_radius(self, inner_radius):
def inner_radius(self, inner_radius: float):
self._inner_radius = inner_radius

@property
def mid_radius(self):
return self._mid_radius

@mid_radius.setter
def mid_radius(self, mid_radius):
def mid_radius(self, mid_radius: float):
self._mid_radius = mid_radius

@property
def outer_radius(self):
return self._outer_radius

@outer_radius.setter
def outer_radius(self, outer_radius):
def outer_radius(self, outer_radius: float):
self._outer_radius = outer_radius

def find_points(self):
Expand Down
10 changes: 4 additions & 6 deletions paramak/parametric_components/center_column_plasma_dependant.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Optional

from paramak import Plasma, RotateMixedShape


Expand Down Expand Up @@ -28,10 +26,10 @@ def __init__(
inner_radius: float,
mid_offset: float,
edge_offset: float,
major_radius: Optional[float] = 450.0,
minor_radius: Optional[float] = 150.0,
triangularity: Optional[float] = 0.55,
elongation: Optional[float] = 2.0,
major_radius: float = 450.0,
minor_radius: float = 150.0,
triangularity: float = 0.55,
elongation: float = 2.0,
**kwargs,
) -> None:

Expand Down
25 changes: 8 additions & 17 deletions paramak/parametric_components/circular_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ def __init__(
flange_overhang: float = 10,
flange_thickness: float = 5,
flange_gap: float = 0,
blank_flange_thickness: Optional[float] = 5,
workplane: Optional[str] = "ZY",
rotation_axis: Optional[str] = "Z",
extrusion_start_offset: Optional[float] = 100,
center_point: Optional[tuple] = (0, 0),
name: Optional[str] = "circular_port_cutter",
blank_flange_thickness: float = 5,
workplane: str = "ZY",
rotation_axis: str = "Z",
extrusion_start_offset: float = 100,
center_point: tuple = (0, 0),
name: str = "circular_port_cutter",
color: Tuple[float, float, float, Optional[float]] = (
0.984,
0.603,
Expand Down Expand Up @@ -72,12 +72,7 @@ def create_solid(self):
A CadQuery solid: A 3D solid volume
"""

# so a positive offset moves extrusion further from axis of azimuthal
# placement rotation
if self.extrusion_start_offset is None:
extrusion_offset = 0.0
else:
extrusion_offset = -self.extrusion_start_offset
extrusion_offset = -self.extrusion_start_offset
flange_gap = -self.flange_gap
extrusion_distance = -self.distance
flange_thickness = self.flange_thickness
Expand Down Expand Up @@ -110,11 +105,7 @@ def create_solid(self):
flange_solid = flange_solid.cut(inner_solid)
solid = solid.union(flange_solid)

# changing value internally so that 0 can be used in additions
if self.blank_flange_thickness is None:
blank_flange_thickness = 0
else:
blank_flange_thickness = self.blank_flange_thickness
blank_flange_thickness = self.blank_flange_thickness

if blank_flange_thickness > 0:
blank_flange_wire = (
Expand Down
19 changes: 10 additions & 9 deletions paramak/parametric_components/constant_thickness_dome.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import math
from paramak import RotateMixedShape, RotateStraightShape, Shape, CuttingWedge
import cadquery as cq
import numbers


class ConstantThicknessDome(RotateMixedShape):
Expand Down Expand Up @@ -46,9 +47,9 @@ def chord_width(self):
return self._chord_width

@chord_width.setter
def chord_width(self, value):
if not isinstance(value, (float, int)):
raise ValueError("ConstantThicknessDome.chord_width must be a number. Not", value)
def chord_width(self, value: float):
if not isinstance(value, numbers.Number):
raise ValueError("ConstantThicknessDome.chord_width must be a float. Not", value)
if value <= 0:
msg = f"ConstantThicknessDome.chord_width must be a positive number above 0. Not {value}"
raise ValueError(msg)
Expand All @@ -59,9 +60,9 @@ def chord_height(self):
return self._chord_height

@chord_height.setter
def chord_height(self, value):
if not isinstance(value, (float, int)):
raise ValueError("ConstantThicknessDome.chord_height must be a number. Not", value)
def chord_height(self, value: float):
if not isinstance(value, numbers.Number):
raise ValueError("ConstantThicknessDome.chord_height must be a float. Not", value)
if value <= 0:
msg = f"ConstantThicknessDome.chord_height must be a positive number above 0. Not {value}"
raise ValueError(msg)
Expand All @@ -72,9 +73,9 @@ def thickness(self):
return self._thickness

@thickness.setter
def thickness(self, value):
if not isinstance(value, (float, int)):
msg = f"VacuumVessel.thickness must be a number. Not {value}"
def thickness(self, value: float):
if not isinstance(value, numbers.Number):
msg = f"VacuumVessel.thickness must be a float. Not {value}"
raise ValueError(msg)
if value <= 0:
msg = f"VacuumVessel.thickness must be a positive number above 0. Not {value}"
Expand Down
4 changes: 1 addition & 3 deletions paramak/parametric_components/coolant_channel_ring_curved.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Optional

import numpy as np

from paramak import SweepCircleShape
Expand Down Expand Up @@ -33,7 +31,7 @@ def __init__(
number_of_coolant_channels: int,
ring_radius: float,
mid_offset: float,
start_angle: Optional[float] = 0.0,
start_angle: float = 0.0,
**kwargs
) -> None:

Expand Down
8 changes: 3 additions & 5 deletions paramak/parametric_components/cutting_wedge.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Optional

from paramak import RotateStraightShape


Expand All @@ -13,7 +11,7 @@ class CuttingWedge(RotateStraightShape):
rotation_angle: Defaults to 180.0.
"""

def __init__(self, height: float, radius: float, rotation_angle: Optional[float] = 180.0, **kwargs) -> None:
def __init__(self, height: float, radius: float, rotation_angle: float = 180.0, **kwargs) -> None:

super().__init__(rotation_angle=rotation_angle, **kwargs)

Expand All @@ -25,15 +23,15 @@ def height(self):
return self._height

@height.setter
def height(self, value):
def height(self, value: float):
self._height = value

@property
def radius(self):
return self._radius

@radius.setter
def radius(self, value):
def radius(self, value: float):
self._radius = value

def find_points(self):
Expand Down
Loading