Skip to content

Commit 7db7b66

Browse files
committed
Replaces string enums with Literals
1 parent 4e78784 commit 7db7b66

File tree

11 files changed

+34
-34
lines changed

11 files changed

+34
-34
lines changed

aerosandbox/aerodynamics/aero_3D/aero_buildup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
softmax_scalefree,
1212
)
1313
from dataclasses import dataclass
14+
from typing import Literal
1415

1516

1617
class AeroBuildup(ExplicitAnalysis):
@@ -52,7 +53,7 @@ def __init__(
5253
airplane: Airplane,
5354
op_point: OperatingPoint,
5455
xyz_ref: np.ndarray | list[float] | None = None,
55-
model_size: str = "small",
56+
model_size: Literal["small", "large"] = "small",
5657
include_wave_drag: bool = True,
5758
):
5859
"""

aerosandbox/atmosphere/atmosphere.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def density(self):
170170

171171
return rho
172172

173-
def density_altitude(self, method: str = "approximate"):
173+
def density_altitude(self, method: Literal["approximate", "exact"] = "approximate"):
174174
"""
175175
Returns the density altitude, in meters.
176176

aerosandbox/dynamics/point_mass/common_point_mass.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import aerosandbox.numpy as np
22
from aerosandbox.common import AeroSandboxObject
33
from abc import ABC, abstractmethod
4-
from typing import Sequence
4+
from typing import Literal, Sequence
55
from aerosandbox import (
66
MassProperties,
77
Opti,
@@ -363,7 +363,7 @@ def add_force(
363363
Fx: float | np.ndarray = 0,
364364
Fy: float | np.ndarray = 0,
365365
Fz: float | np.ndarray = 0,
366-
axes: str = "wind",
366+
axes: Literal["geometry", "body", "wind", "stability", "earth"] = "wind",
367367
) -> None:
368368
"""
369369
Adds a force (in whichever axis system you choose) to this Dynamics instance.
@@ -423,14 +423,14 @@ def op_point(self):
423423
def draw(
424424
self,
425425
vehicle_model: "Airplane | PolyData | None" = None,
426-
backend: str = "pyvista",
426+
backend: Literal["pyvista"] = "pyvista",
427427
plotter=None,
428428
draw_axes: bool = True,
429429
draw_global_axes: bool = True,
430430
draw_global_grid: bool = True,
431431
scale_vehicle_model: float | None = None,
432432
n_vehicles_to_draw: int = 10,
433-
cg_axes: str = "geometry",
433+
cg_axes: Literal["geometry", "body", "wind", "stability"] = "geometry",
434434
draw_trajectory_line: bool = True,
435435
trajectory_line_color=None,
436436
draw_altitude_drape: bool = True,

aerosandbox/geometry/airfoil/airfoil_families.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def get_kulfan_parameters(
280280
n_points_per_side: int = _default_n_points_per_side,
281281
normalize_coordinates: bool = True,
282282
use_leading_edge_modification: bool = True,
283-
method: str = "least_squares",
283+
method: Literal["least_squares", "opti"] = "least_squares",
284284
) -> dict[str, np.ndarray | float]:
285285
"""
286286
Given a set of airfoil coordinates, reconstructs the Kulfan parameters that would recreate that airfoil. Uses a

aerosandbox/geometry/airplane.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import itertools
22
from aerosandbox import AeroSandboxObject
33
from aerosandbox.geometry.common import *
4-
from typing import Any
5-
from typing import Sequence
4+
from typing import Any, Literal, Sequence
65
import aerosandbox.geometry.mesh_utilities as mesh_utils
76
from aerosandbox.geometry.wing import Wing
87
from aerosandbox.geometry.fuselage import Fuselage
@@ -223,10 +222,10 @@ def mesh_body(
223222

224223
def draw(
225224
self,
226-
backend: str = "pyvista",
225+
backend: Literal["matplotlib", "pyvista", "plotly", "trimesh"] = "pyvista",
227226
thin_wings: bool = False,
228227
ax=None,
229-
use_preset_view_angle: str | None = None,
228+
use_preset_view_angle: Literal["XY", "-XY", "XZ", "-XZ", "YZ", "-YZ", "left_isometric", "right_isometric"] | None = None,
230229
set_background_pane_color: str | tuple[float, float, float] | None = None,
231230
set_background_pane_alpha: float | None = None,
232231
set_lims: bool = True,
@@ -386,7 +385,7 @@ def draw_wireframe(
386385
thin_linewidth=0.2,
387386
thick_linewidth=0.5,
388387
fuselage_longeron_theta=None,
389-
use_preset_view_angle: str | None = None,
388+
use_preset_view_angle: Literal["XY", "-XY", "XZ", "-XZ", "YZ", "-YZ", "left_isometric", "right_isometric"] | None = None,
390389
set_background_pane_color: str | tuple[float, float, float] | None = None,
391390
set_background_pane_alpha: float | None = None,
392391
set_lims: bool = True,
@@ -649,7 +648,7 @@ def reshape(x):
649648
def draw_three_view(
650649
self,
651650
axs=None,
652-
style: str = "shaded",
651+
style: Literal["shaded", "wireframe"] = "shaded",
653652
show: bool = True,
654653
) -> np.ndarray:
655654
"""

aerosandbox/geometry/fuselage.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
from aerosandbox import AeroSandboxObject
44
from aerosandbox.geometry.common import *
5-
from typing import Any, Callable
6-
from typing import Sequence
5+
from typing import Any, Callable, Literal, Sequence
76
import copy
87
from aerosandbox.numpy.typing import Scalar # Type alias including CasADi types
98

@@ -117,7 +116,7 @@ def __repr__(self) -> str:
117116

118117
def add_loft(
119118
self,
120-
kind: str,
119+
kind: Literal["linear", "ellipsoid-nose"],
121120
to_xsec: "FuselageXSec",
122121
from_xsec: "FuselageXSec | None" = None,
123122
n_points: int = 5,
@@ -191,7 +190,7 @@ def area_wetted(self) -> float:
191190

192191
def area_projected(
193192
self,
194-
type: str = "XY",
193+
type: Literal["XY", "XZ"] = "XY",
195194
) -> float:
196195
"""
197196
Returns the area of the fuselage as projected onto one of the principal planes.
@@ -233,7 +232,7 @@ def area_base(self) -> float:
233232

234233
def fineness_ratio(
235234
self,
236-
assumed_shape="cylinder",
235+
assumed_shape: Literal["cylinder", "sears-haack"] = "cylinder",
237236
) -> float:
238237
"""
239238
Approximates the fineness ratio using the volume and length. The fineness ratio of a fuselage is defined as:
@@ -305,7 +304,7 @@ def volume(self, _sectional: bool = False) -> float | list[float]:
305304

306305
def x_centroid_projected(
307306
self,
308-
type: str = "XY",
307+
type: Literal["XY", "XZ"] = "XY",
309308
) -> float:
310309
"""
311310
Returns the x_g coordinate of the centroid of the planform area.
@@ -349,7 +348,7 @@ def x_centroid_projected(
349348

350349
def mesh_body(
351350
self,
352-
method="quad",
351+
method: Literal["quad", "tri"] = "quad",
353352
tangential_resolution: int = 36,
354353
) -> tuple[np.ndarray, np.ndarray]:
355354
"""
@@ -906,7 +905,7 @@ def get_3D_coordinates(
906905
self.xyz_c[2] + y * yg_local[2] + z * zg_local[2],
907906
)
908907

909-
def equivalent_radius(self, preserve="area") -> float:
908+
def equivalent_radius(self, preserve: Literal["area", "perimeter"] = "area") -> float:
910909
"""
911910
Computes an equivalent radius for non-circular cross-sections. This may be necessary when doing analysis that
912911
uses axisymmetric assumptions.

aerosandbox/geometry/wing.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from aerosandbox.common import AeroSandboxObject
22
from aerosandbox.geometry.common import *
3-
from typing import Any, Callable, Sequence
3+
from typing import Any, Callable, Literal, Sequence
44
from aerosandbox.geometry.airfoil import Airfoil
55
from numpy import pi
66
import aerosandbox.numpy as np
@@ -138,7 +138,7 @@ def translate(self, xyz: np.ndarray | Sequence[float]) -> "Wing":
138138

139139
def span(
140140
self,
141-
type: str = "yz",
141+
type: Literal["xyz", "xy", "top", "yz", "front", "xz", "side", "x", "y", "z"] = "yz",
142142
include_centerline_distance=False,
143143
_sectional: bool = False,
144144
) -> float | list[float]:
@@ -287,7 +287,7 @@ def span(
287287

288288
def area(
289289
self,
290-
type: str = "planform",
290+
type: Literal["planform", "wetted", "xy", "projected", "top", "xz", "side", "yz"] = "planform",
291291
include_centerline_distance=False,
292292
_sectional: bool = False,
293293
) -> float | list[float]:
@@ -413,7 +413,7 @@ def area(
413413

414414
def aspect_ratio(
415415
self,
416-
type: str = "geometric",
416+
type: Literal["geometric", "effective"] = "geometric",
417417
) -> float:
418418
"""
419419
Computes the aspect ratio of the wing, with options for various ways of measuring this.
@@ -765,7 +765,7 @@ def set_control_surface_deflections(
765765
def control_surface_area(
766766
self,
767767
by_name: str | None = None,
768-
type: str | None = "planform",
768+
type: Literal["planform", "wetted", "xy", "projected", "top", "xz", "side"] | None = "planform",
769769
) -> float:
770770
"""
771771
Computes the total area of all control surfaces on this wing, optionally filtered by their name.
@@ -830,7 +830,7 @@ def control_surface_area(
830830

831831
def mesh_body(
832832
self,
833-
method="quad",
833+
method: Literal["tri", "quad"] = "quad",
834834
chordwise_resolution: int = 36,
835835
chordwise_spacing_function_per_side: Callable[[float, float, int], np.ndarray] = np.cosspace,
836836
mesh_surface: bool = True,
@@ -994,7 +994,7 @@ def add_face(*indices):
994994

995995
def mesh_thin_surface(
996996
self,
997-
method="tri",
997+
method: Literal["tri", "quad"] = "tri",
998998
chordwise_resolution: int = 36,
999999
chordwise_spacing_function: Callable[[float, float, int], np.ndarray] = np.cosspace,
10001000
add_camber: bool = True,

aerosandbox/library/aerodynamics/components.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def CDA_control_surface_gaps(
155155
return CDA_side_gaps + CDA_hinge_gap
156156

157157

158-
def CDA_protruding_bolt_or_rivet(diameter: float, kind: str = "flush_rivet"):
158+
def CDA_protruding_bolt_or_rivet(diameter: float, kind: Literal["flush_rivet", "round_rivet", "flat_head_bolt", "round_head_bolt", "cylindrical_bolt", "hex_bolt"] = "flush_rivet"):
159159
"""
160160
Computes the drag area (CDA) of a protruding bolt or rivet.
161161

aerosandbox/modeling/splines/hermite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def cubic_hermite_patch(
3333
f_b: float,
3434
dfdx_a: float,
3535
dfdx_b: float,
36-
extrapolation: str = "continue",
36+
extrapolation: Literal["continue", "clip"] = "continue",
3737
) -> float | np.ndarray:
3838
"""
3939
Computes the cubic Hermite polynomial patch that passes through the given endpoints and endpoint derivatives.

aerosandbox/performance/operating_point.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from aerosandbox.common import AeroSandboxObject
22
from aerosandbox import Atmosphere
33
import aerosandbox.numpy as np
4-
from typing import Sequence
4+
from typing import Literal, Sequence
55
from aerosandbox.tools.string_formatting import trim_string
66
import inspect
77
from aerosandbox.numpy.typing import Vectorizable
@@ -334,8 +334,8 @@ def convert_axes(
334334
x_from: Vectorizable,
335335
y_from: Vectorizable,
336336
z_from: Vectorizable,
337-
from_axes: str,
338-
to_axes: str,
337+
from_axes: Literal["geometry", "body", "wind", "stability"],
338+
to_axes: Literal["geometry", "body", "wind", "stability"],
339339
) -> tuple[Vectorizable, Vectorizable, Vectorizable]:
340340
"""
341341
Converts a vector [x_from, y_from, z_from], as given in the `from_axes` frame, to an equivalent vector [x_to,

0 commit comments

Comments
 (0)