Skip to content

Commit 0d261ff

Browse files
committed
Revert "Disallow function calls in default arguments"
This reverts commit 12a0a6a.
1 parent 101436e commit 0d261ff

5 files changed

Lines changed: 13 additions & 37 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ extend-ignore = [
274274
"RUF015", # next(iter(...)) instead of list(...)[0]
275275
"E501", # line too long
276276
"B905", # `zip()` without an explicit `strict=` parameter
277+
"B008", # TODO: Disallow function calls in default arguments
277278
"UP007", # TODO: Remove once Python >= 3.10
278279
"NPY002", # TODO: Revisit RNG handling
279280
]

tidy3d/components/grid/grid_spec.py

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,9 +1073,9 @@ def from_layer_bounds(
10731073
min_steps_along_axis: np.PositiveFloat = None,
10741074
bounds_refinement: GridRefinement = None,
10751075
bounds_snapping: Literal["bounds", "lower", "upper", "center"] = "lower",
1076-
corner_finder: CornerFinderSpec = None,
1076+
corner_finder: CornerFinderSpec = CornerFinderSpec(),
10771077
corner_snapping: bool = True,
1078-
corner_refinement: GridRefinement = None,
1078+
corner_refinement: GridRefinement = GridRefinement(),
10791079
refinement_inside_sim_only: bool = True,
10801080
gap_meshing_iters: pd.NonNegativeInt = 1,
10811081
dl_min_from_gap_width: bool = True,
@@ -1115,11 +1115,6 @@ def from_layer_bounds(
11151115
>>> layer = LayerRefinementSpec.from_layer_bounds(axis=2, bounds=(0,1))
11161116
11171117
"""
1118-
if corner_finder is None:
1119-
corner_finder = CornerFinderSpec()
1120-
if corner_refinement is None:
1121-
corner_refinement = GridRefinement()
1122-
11231118
center = Box.unpop_axis((bounds[0] + bounds[1]) / 2, (0, 0), axis)
11241119
size = Box.unpop_axis((bounds[1] - bounds[0]), (inf, inf), axis)
11251120

@@ -1147,9 +1142,9 @@ def from_bounds(
11471142
min_steps_along_axis: np.PositiveFloat = None,
11481143
bounds_refinement: GridRefinement = None,
11491144
bounds_snapping: Literal["bounds", "lower", "upper", "center"] = "lower",
1150-
corner_finder: CornerFinderSpec = None,
1145+
corner_finder: CornerFinderSpec = CornerFinderSpec(),
11511146
corner_snapping: bool = True,
1152-
corner_refinement: GridRefinement = None,
1147+
corner_refinement: GridRefinement = GridRefinement(),
11531148
refinement_inside_sim_only: bool = True,
11541149
gap_meshing_iters: pd.NonNegativeInt = 1,
11551150
dl_min_from_gap_width: bool = True,
@@ -1191,11 +1186,6 @@ def from_bounds(
11911186
>>> layer = LayerRefinementSpec.from_bounds(axis=2, rmin=(0,0,0), rmax=(1,1,1))
11921187
11931188
"""
1194-
if corner_finder is None:
1195-
corner_finder = CornerFinderSpec()
1196-
if corner_refinement is None:
1197-
corner_refinement = GridRefinement()
1198-
11991189
box = Box.from_bounds(rmin=rmin, rmax=rmax)
12001190
if axis is None:
12011191
axis = np.argmin(box.size)
@@ -1222,9 +1212,9 @@ def from_structures(
12221212
min_steps_along_axis: np.PositiveFloat = None,
12231213
bounds_refinement: GridRefinement = None,
12241214
bounds_snapping: Literal["bounds", "lower", "upper", "center"] = "lower",
1225-
corner_finder: CornerFinderSpec = None,
1215+
corner_finder: CornerFinderSpec = CornerFinderSpec(),
12261216
corner_snapping: bool = True,
1227-
corner_refinement: GridRefinement = None,
1217+
corner_refinement: GridRefinement = GridRefinement(),
12281218
refinement_inside_sim_only: bool = True,
12291219
gap_meshing_iters: pd.NonNegativeInt = 1,
12301220
dl_min_from_gap_width: bool = True,
@@ -1259,10 +1249,6 @@ def from_structures(
12591249
Take into account autodetected minimal PEC gap width when determining ``dl_min``.
12601250
12611251
"""
1262-
if corner_finder is None:
1263-
corner_finder = CornerFinderSpec()
1264-
if corner_refinement is None:
1265-
corner_refinement = GridRefinement()
12661252

12671253
all_bounds = tuple(structure.geometry.bounds for structure in structures)
12681254
rmin = tuple(min(b[i] for b, _ in all_bounds) for i in range(3))
@@ -2734,7 +2720,7 @@ def auto(
27342720
layer_refinement_specs: list[LayerRefinementSpec] = (),
27352721
dl_min: pd.NonNegativeFloat = 0.0,
27362722
min_steps_per_sim_size: pd.PositiveFloat = 10.0,
2737-
mesher: MesherType = None,
2723+
mesher: MesherType = GradedMesher(),
27382724
) -> GridSpec:
27392725
"""Use the same :class:`AutoGrid` along each of the three directions.
27402726
@@ -2768,8 +2754,6 @@ def auto(
27682754
GridSpec
27692755
:class:`GridSpec` with the same automatic nonuniform grid settings in each direction.
27702756
"""
2771-
if mesher is None:
2772-
mesher = GradedMesher()
27732757

27742758
grid_1d = AutoGrid(
27752759
min_steps_per_wvl=min_steps_per_wvl,
@@ -2813,7 +2797,7 @@ def quasiuniform(
28132797
max_scale: pd.PositiveFloat = 1.4,
28142798
override_structures: list[StructureType] = (),
28152799
snapping_points: tuple[CoordinateOptional, ...] = (),
2816-
mesher: MesherType = None,
2800+
mesher: MesherType = GradedMesher(),
28172801
) -> GridSpec:
28182802
"""Use the same :class:`QuasiUniformGrid` along each of the three directions.
28192803
@@ -2837,8 +2821,6 @@ def quasiuniform(
28372821
GridSpec
28382822
:class:`GridSpec` with the same uniform grid size in each direction.
28392823
"""
2840-
if mesher is None:
2841-
mesher = GradedMesher()
28422824

28432825
grid_1d = QuasiUniformGrid(dl=dl, max_scale=max_scale, mesher=mesher)
28442826
return cls(

tidy3d/components/mode/solver.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,8 @@ def solver_diagonal(
472472
# code associated with these options is included below in case it's useful in the future
473473
enable_preconditioner = False
474474
analyze_conditioning = False
475-
_threshold = 0.9 * np.abs(pec_val)
476475

477-
def incidence_matrix_for_pec(eps_vec, threshold=_threshold):
476+
def incidence_matrix_for_pec(eps_vec, threshold=0.9 * np.abs(pec_val)):
478477
"""Incidence matrix indicating non-PEC entries associated with 'eps_vec'."""
479478
nnz = eps_vec[np.abs(eps_vec) < threshold]
480479
eps_nz = eps_vec.copy()

tidy3d/plugins/dispersion/web.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def run(
314314
num_poles: PositiveInt = 1,
315315
num_tries: PositiveInt = 50,
316316
tolerance_rms: NonNegativeFloat = 1e-2,
317-
advanced_param: AdvancedFitterParam = None,
317+
advanced_param: AdvancedFitterParam = AdvancedFitterParam(),
318318
) -> tuple[PoleResidue, float]:
319319
"""Execute the data fit using the stable fitter in the server.
320320
@@ -336,8 +336,6 @@ def run(
336336
Tuple[:class:`.PoleResidue`, float]
337337
Best results of multiple fits: (dispersive medium, RMS error).
338338
"""
339-
if advanced_param is None:
340-
advanced_param = AdvancedFitterParam()
341339
task = FitterData.create(fitter, num_poles, num_tries, tolerance_rms, advanced_param)
342340
return task.run()
343341

@@ -359,9 +357,7 @@ def fit(
359357
num_tries: PositiveInt = 50,
360358
tolerance_rms: NonNegativeFloat = 1e-2,
361359
guess: PoleResidue = None,
362-
advanced_param: AdvancedFitterParam = None,
360+
advanced_param: AdvancedFitterParam = AdvancedFitterParam(),
363361
) -> tuple[PoleResidue, float]:
364362
"""Deprecated."""
365-
if advanced_param is None:
366-
advanced_param = AdvancedFitterParam()
367363
return run(self, num_poles, num_tries, tolerance_rms, advanced_param)

tidy3d/plugins/microwave/array_factor.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ def array_factor(
712712
theta: Union[float, ArrayLike],
713713
phi: Union[float, ArrayLike],
714714
frequency: Union[NonNegativeFloat, ArrayLike],
715-
medium: MediumType3D = None,
715+
medium: MediumType3D = Medium(),
716716
) -> ArrayLike:
717717
"""
718718
Compute the array factor for a 3D antenna array.
@@ -731,8 +731,6 @@ def array_factor(
731731
ArrayLike
732732
Array factor values for each combination of theta and phi.
733733
"""
734-
if medium is None:
735-
medium = Medium()
736734

737735
# Convert all inputs to numpy arrays
738736
theta_array = np.atleast_1d(theta)

0 commit comments

Comments
 (0)