-
Notifications
You must be signed in to change notification settings - Fork 123
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
Sourcery refactored master branch #67
base: master
Are you sure you want to change the base?
Conversation
7576a42
to
4722fdd
Compare
print("running %s ..." % example_name, end="") | ||
print(f"running {example_name} ...", end="") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function worker
refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring
)
ais_boxshp = display.DisplayShape(boxshp, update=True)[0] | ||
return ais_boxshp | ||
return display.DisplayShape(boxshp, update=True)[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function build_shape
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
for i in range(n_rotations): | ||
for _ in range(n_rotations): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function rotating_cube_1_axis
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
for i in range(n_rotations): | ||
for _ in range(n_rotations): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function rotating_cube_2_axis
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
x, y, z = [random.uniform(0, 1) for i in range(3)] | ||
x, y, z = [random.uniform(0, 1) for _ in range(3)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function random_pnt
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
loc = TopLoc_Location(trsf) | ||
return loc | ||
return TopLoc_Location(trsf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function location_from_vector
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
"http://m-selig.ae.illinois.edu/ads/coord_seligFmt/%s.dat" % self.profile | ||
f"http://m-selig.ae.illinois.edu/ads/coord_seligFmt/{self.profile}.dat" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function UiucAirfoil.make_shape
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
face = n_sided.Face() | ||
return face | ||
return n_sided.Face() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function make_n_sided
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if isinstance(pt, list) or isinstance(pt, tuple): | ||
if isinstance(pt, (list, tuple)): | ||
for i in pt: | ||
poly.Add(i) | ||
else: | ||
poly.Add(pt) | ||
poly.Build() | ||
poly.Close() | ||
result = poly.Wire() | ||
return result | ||
return poly.Wire() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function make_closed_polygon
refactored with the following changes:
- Merge isinstance calls (
merge-isinstance
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
edges = [i for i in TopologyExplorer(poly).edges()] | ||
edges = list(TopologyExplorer(poly).edges()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function geom_plate
refactored with the following changes:
- Replace identity comprehension with call to collection constructor (
identity-comprehension
)
print("Goal: %s radius: %s" % (i, rcs.curr_radius)) | ||
print(f"Goal: {i} radius: {rcs.curr_radius}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function solve_radius
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
face = make_face(plate.Surface(), uMin, uMax, vMin, vMax, 1e-6) | ||
return face | ||
return make_face(plate.Surface(), uMin, uMax, vMin, vMax, 1e-6) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function build_geom_plate
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
shp = cut.Shape() | ||
return shp | ||
return cut.Shape() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function boolean_cut
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
f3 = boolean_cut(f, f2) | ||
return f3 | ||
return boolean_cut(f, f2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function make_face_to_contour_from
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
# loop over faces | ||
fc_idx = 1 | ||
|
||
for face in expl.faces(): | ||
for fc_idx, face in enumerate(expl.faces(), start=1): | ||
print("=== Face %i ===" % fc_idx) | ||
surf = BRepAdaptor_Surface(face, True) | ||
surf_type = surf.GetType() | ||
# check each of the is a BSpline surface | ||
# it should be, since we used the nurbs converter before | ||
if not surf_type == GeomAbs_BSplineSurface: | ||
if surf_type != GeomAbs_BSplineSurface: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 37-81
refactored with the following changes:
- Replace manual loop counter with call to enumerate (
convert-to-enumerate
) - Simplify logical expression using De Morgan identities (
de-morgan
)
This removes the following comments ( why? ):
# loop over faces
# Remove the revolved shape | ||
cut = BRepAlgoAPI_Cut(base, moved_shape).Shape() | ||
return cut | ||
return BRepAlgoAPI_Cut(base, moved_shape).Shape() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function revolved_cut
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
This removes the following comments ( why? ):
# Remove the revolved shape
revolved_shape = revolved_cut(fused_shape) | ||
return revolved_shape | ||
return revolved_cut(fused_shape) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function generate_demo
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
cut_2 = BRepAlgoAPI_Cut(cut_1, rounding_cut_2).Shape() | ||
|
||
return cut_2 | ||
return BRepAlgoAPI_Cut(cut_1, rounding_cut_2).Shape() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function round_tooth
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if inter_1.Point(1).X() > 0: | ||
p1 = inter_1.Point(1) | ||
else: | ||
p1 = inter_1.Point(2) | ||
|
||
if inter_2.Point(1).X() > 0: | ||
p2 = inter_2.Point(1) | ||
else: | ||
p2 = inter_2.Point(2) | ||
|
||
if inter_3.Point(1).X() > 0: | ||
p3 = inter_3.Point(1) | ||
else: | ||
p3 = inter_3.Point(2) | ||
|
||
if inter_4.Point(1).X() > 0: | ||
p4 = inter_4.Point(1) | ||
else: | ||
p4 = inter_4.Point(2) | ||
|
||
p1 = inter_1.Point(1) if inter_1.Point(1).X() > 0 else inter_1.Point(2) | ||
p2 = inter_2.Point(1) if inter_2.Point(1).X() > 0 else inter_2.Point(2) | ||
p3 = inter_3.Point(1) if inter_3.Point(1).X() > 0 else inter_3.Point(2) | ||
p4 = inter_4.Point(1) if inter_4.Point(1).X() > 0 else inter_4.Point(2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function cut_out
refactored with the following changes:
- Replace if statement with if expression [×4] (
assign-if-exp
)
sprocket = cut_out(mountable_disc) | ||
return sprocket | ||
return cut_out(mountable_disc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function build_sprocket
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
_str_slices.append(":" + str(i * n) + " ") | ||
_str_slices.append(f":{str(i * n)} ") | ||
elif i == n_procs: | ||
# does a little extra work if the number of slices | ||
# isn't divisible by n_procs | ||
slices.append(z_slices[(i - 1) * n :]) | ||
_str_slices.append(str((i - 1) * n) + ": ") | ||
_str_slices.append(f"{str((i - 1) * n)}: ") | ||
print("last slice", len(z_slices[(i - 1) * n :])) | ||
else: | ||
slices.append(z_slices[(i - 1) * n : i * n]) | ||
_str_slices.append(" %s:%s " % ((i - 1) * n, i * n)) | ||
_str_slices.append(f" {(i - 1) * n}:{i * n} ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function run
refactored with the following changes:
- Use f-string instead of string concatenation [×3] (
use-fstring-for-concatenation
) - Replace interpolated string formatting with f-string [×3] (
replace-interpolation-with-fstring
)
print("Cube mass = %s" % mass) | ||
print(f"Cube mass = {mass}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function cube_inertia_properties
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
shp_idx = 1 | ||
for face in t.faces(): | ||
for shp_idx, face in enumerate(t.faces(), start=1): | ||
brepgprop_SurfaceProperties(face, props) | ||
face_surf = props.Mass() | ||
print("Surface for face nbr %i : %f" % (shp_idx, face_surf)) | ||
shp_idx += 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function shape_faces_surface
refactored with the following changes:
- Replace manual loop counter with call to enumerate (
convert-to-enumerate
)
if not number_of_normals == number_of_vertices: | ||
if number_of_normals != number_of_vertices: | ||
raise AssertionError("wrong number of normals returned by the tessellator") | ||
|
||
# if HAVE_NUMPY, we try to reshape the tuple so that it is of | ||
# a ndarray such as [[x1, y1, z1], [x2, y2, z2], ...] | ||
# | ||
if HAVE_NUMPY: | ||
vertices = np.array(vertices_position).reshape(int(number_of_vertices / 3), 3) | ||
normals = np.array(normals).reshape(int(number_of_vertices / 3), 3) | ||
vertices = np.array(vertices_position).reshape(number_of_vertices // 3, 3) | ||
normals = np.array(normals).reshape(number_of_vertices // 3, 3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 50-58
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
) - Simplify division expressions [×2] (
simplify-division
)
line3 = Geom2d_Line(P32d, gp_Dir2d((0.9 - 0.02), (0.1 - 0.1))) | ||
line3 = Geom2d_Line(P32d, gp_Dir2d(0.9 - 0.02, 0.0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function face
refactored with the following changes:
- Simplify binary operation (
bin-op-identity
)
if abs(dx) <= tolerance and abs(dy) <= tolerance: | ||
# zooming at a near nil value can segfault the opengl viewer | ||
pass | ||
else: | ||
if abs(dx) > tolerance or abs(dy) > tolerance: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function GLWidget.on_zoom_area
refactored with the following changes:
- Swap if/else to remove empty if body (
remove-pass-body
)
This removes the following comments ( why? ):
# zooming at a near nil value can segfault the opengl viewer
perform_action = False | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function GLWidget._dispatch_camera_command_actions
refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if abs(dx) <= tolerance and abs(dy) <= tolerance: | ||
pass | ||
|
||
else: | ||
if abs(dx) > tolerance or abs(dy) > tolerance: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function GLWidget.drawBox
refactored with the following changes:
- Swap if/else to remove empty if body (
remove-pass-body
)
idx = 0 | ||
for i in range(n_toruses): | ||
for idx, _ in enumerate(range(n_toruses)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 33-52
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
) - Replace manual loop counter with call to enumerate (
convert-to-enumerate
)
for i in range(100): | ||
for _ in range(100): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 30-30
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
Branch
master
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
master
branch, then run:Help us improve this pull request!