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

Check variable assignments that immediately return #5911

Merged
merged 23 commits into from May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
99c756f
Check variable assignments that immediately return
tkoyama010 Apr 12, 2024
69fbeed
Apply suggestions from code review
tkoyama010 Apr 12, 2024
435e303
Merge branch 'main' into maint/ret
tkoyama010 Apr 12, 2024
c900900
Merge branch 'main' into maint/ret
tkoyama010 Apr 12, 2024
d8c7bdc
Merge branch 'main' into maint/ret
tkoyama010 May 5, 2024
3f74c4e
Update doc/source/make_tables.py
tkoyama010 May 5, 2024
818f959
Merge branch 'main' into maint/ret
pyvista-bot May 5, 2024
d4a7881
Merge branch 'main' into maint/ret
pyvista-bot May 5, 2024
e6fef4e
Merge branch 'main' into maint/ret
pyvista-bot May 6, 2024
4e716af
Merge branch 'main' into maint/ret
pyvista-bot May 7, 2024
5696323
Merge branch 'main' into maint/ret
pyvista-bot May 7, 2024
87cb052
Merge branch 'main' into maint/ret
pyvista-bot May 8, 2024
e1399f2
Merge branch 'main' into maint/ret
pyvista-bot May 9, 2024
b81390a
Merge branch 'main' into maint/ret
pyvista-bot May 9, 2024
4b1e5c2
Update test_dataset_filters.py
tkoyama010 May 9, 2024
e34a008
Apply suggestions from code review
tkoyama010 May 15, 2024
c9c8ee3
Merge branch 'main' into maint/ret
tkoyama010 May 15, 2024
0602427
Update dataset.py
tkoyama010 May 15, 2024
c3b635c
Apply suggestions from code review
tkoyama010 May 15, 2024
abb2f07
Update dataset.py
tkoyama010 May 15, 2024
86b1f92
Update pyvista/core/dataset.py
tkoyama010 May 15, 2024
f170b21
Apply suggestions from code review
tkoyama010 May 15, 2024
90e56ab
Merge branch 'main' into maint/ret
tkoyama010 May 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions doc/source/make_external_gallery.py
Expand Up @@ -13,8 +13,7 @@ def format_icon(title, link, image):

.. image:: ../images/external-examples/{}
"""
content = body.format(title, link, image)
return content
return body.format(title, link, image)


class Example:
Expand Down
30 changes: 10 additions & 20 deletions doc/source/make_tables.py
Expand Up @@ -851,8 +851,7 @@ def _generate_carousel_badges(badges: List[_BaseDatasetBadge]):
elif isinstance(badge, _BaseDatasetBadge):
raise NotImplementedError(f'No implementation for badge type {type(badge)}.')
all_badges = module_badges + datatype_badges + special_badges + category_badges
rst = ' '.join([badge.generate() for badge in all_badges])
return rst
return ' '.join([badge.generate() for badge in all_badges])

@staticmethod
def _generate_celltype_badges(badges: List[_BaseDatasetBadge]):
Expand Down Expand Up @@ -931,8 +930,7 @@ def _format_and_indent_from_template(*args, template=None, indent_level=None):
assert template is not None
assert indent_level is not None
formatted = template.format(*args)
indented = _indent_multi_line_string(formatted, indent_level=indent_level)
return indented
return _indent_multi_line_string(formatted, indent_level=indent_level)

@classmethod
def _generate_field_grid(cls, field_name, field_values):
Expand Down Expand Up @@ -992,22 +990,20 @@ def _create_header_block(cls, index_name, header_name, carousel_badges):
@classmethod
def _create_image_block(cls, img_path):
"""Generate rst block for the dataset image."""
block = cls._format_and_indent_from_template(
return cls._format_and_indent_from_template(
img_path,
template=cls.image_template,
indent_level=cls.GRID_ITEM_INDENT_LEVEL,
)
return block

@classmethod
def _create_info_block(cls, func_ref, func_doc):
block = cls._format_and_indent_from_template(
return cls._format_and_indent_from_template(
func_ref,
func_doc,
template=cls.dataset_info_template,
indent_level=cls.GRID_ITEM_INDENT_LEVEL,
)
return block

@classmethod
def _create_dataset_props_block(
Expand All @@ -1023,10 +1019,9 @@ def _create_dataset_props_block(
('Spacing', spacing),
('N Arrays', n_arrays),
]
dataset_fields_block = cls._generate_field_block(
return cls._generate_field_block(
dataset_fields, indent_level=cls.GRID_ITEM_FIELDS_INDENT_LEVEL
)
return dataset_fields_block

@classmethod
def _create_file_props_block(cls, file_size, num_files, file_ext, reader_type):
Expand All @@ -1036,21 +1031,19 @@ def _create_file_props_block(cls, file_size, num_files, file_ext, reader_type):
('File Ext', file_ext),
('Reader', reader_type),
]
file_info_fields_block = DatasetCard._generate_field_block(
return DatasetCard._generate_field_block(
file_info_fields, indent_level=cls.GRID_ITEM_FIELDS_INDENT_LEVEL
)
return file_info_fields_block

@classmethod
def _create_footer_block(cls, datasource_links):
# indent links one level from the dropdown directive in template
datasource_links = _indent_multi_line_string(datasource_links, indent_level=1)
footer_block = cls._format_and_indent_from_template(
return cls._format_and_indent_from_template(
datasource_links,
template=cls.footer_template,
indent_level=cls.HEADER_FOOTER_INDENT_LEVEL,
)
return footer_block


class DatasetPropsGenerator:
Expand All @@ -1074,8 +1067,7 @@ def generate_file_ext(loader: _dataset_loader._FileProps):
# Multiple extensions are comma-separated
file_ext = loader.unique_extension
file_ext = [file_ext] if isinstance(file_ext, str) else file_ext
file_ext = '\n'.join(['``\'' + ext + '\'``' for ext in file_ext])
return file_ext
return '\n'.join(['``\'' + ext + '\'``' for ext in file_ext])

@staticmethod
def generate_reader_type(loader: _dataset_loader._FileProps):
Expand All @@ -1096,14 +1088,13 @@ def generate_reader_type(loader: _dataset_loader._FileProps):
@staticmethod
def generate_dataset_type(loader: _dataset_loader._FileProps):
"""Format dataset type(s) with doc references to dataset class(es)."""
dataset_type = (
return (
repr(loader.unique_dataset_type)
.replace('<class \'', ':class:`~')
.replace('\'>', '`')
.replace('(', '')
.replace(')', '')
).replace(', ', '\n')
return dataset_type

@staticmethod
def _generate_dataset_repr(loader: _dataset_loader._FileProps, indent_level: int) -> str:
Expand Down Expand Up @@ -1135,8 +1126,7 @@ def _rst_link(name, url):
url_dict[url] = name

rst_links = [_rst_link(name, url) for url, name in url_dict.items()]
rst_links = '\n'.join(rst_links)
return rst_links
return '\n'.join(rst_links)

@staticmethod
def generate_n_cells(loader):
Expand Down
3 changes: 1 addition & 2 deletions examples/00-load/create-point-cloud.py
Expand Up @@ -96,8 +96,7 @@ def generate_points(subset=0.02):
def compute_vectors(mesh):
origin = mesh.center
vectors = mesh.points - origin
vectors = vectors / np.linalg.norm(vectors, axis=1)[:, None]
return vectors
return vectors / np.linalg.norm(vectors, axis=1)[:, None]


vectors = compute_vectors(point_cloud)
Expand Down
3 changes: 1 addition & 2 deletions examples/02-plot/spherical.py
Expand Up @@ -40,8 +40,7 @@ def _cell_bounds(points, bound_position=0.5):
raise ValueError("Only 1D points are allowed.")
diffs = np.diff(points)
delta = diffs[0] * bound_position
bounds = np.concatenate([[points[0] - delta], points + delta])
return bounds
return np.concatenate([[points[0] - delta], points + delta])


# First, create some dummy data
Expand Down
3 changes: 1 addition & 2 deletions examples/03-widgets/sphere-widget.py
Expand Up @@ -123,8 +123,7 @@ def get_colors(n):

cycler = mpl.rcParams['axes.prop_cycle']
colors = cycle(cycler)
colors = [next(colors)['color'] for i in range(n)]
return colors
return [next(colors)['color'] for i in range(n)]


# Create a grid to interpolate to
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Expand Up @@ -335,6 +335,9 @@ ignore = [
"SIM117",
# https://github.com/pyvista/pyvista/pull/5837
"SIM118",
"RET505",
"RET506",
"RET507",
tkoyama010 marked this conversation as resolved.
Show resolved Hide resolved
]
fixable = ["ALL"]
unfixable = []
Expand All @@ -359,7 +362,7 @@ extend-select = [
"PLR1714",
"PT",
"PTH",
"RET501",
"RET",
"RSE",
"RUF002",
"RUF003",
Expand Down
2 changes: 1 addition & 1 deletion pyvista/core/dataobject.py
Expand Up @@ -242,7 +242,7 @@ def head(self, display=True, html=None):
from IPython.display import HTML, display as _display

_display(HTML(fmt))
return
return None
return fmt
# Otherwise return a string that is Python console friendly
fmt = f"{type(self).__name__} ({hex(id(self))})\n"
Expand Down
1 change: 1 addition & 0 deletions pyvista/core/dataset.py
Expand Up @@ -2935,6 +2935,7 @@ def generate_ids(i: int, connections: str): # numpydoc ignore=GL08
return cell.get_edge(i).GetPointIds()
elif connections == "faces":
return cell.get_face(i).GetPointIds()
return None
tkoyama010 marked this conversation as resolved.
Show resolved Hide resolved

neighbors = set()
for i in iterators[connections]:
Expand Down
19 changes: 5 additions & 14 deletions pyvista/core/filters/data_set.py
Expand Up @@ -655,15 +655,14 @@ def clip_surface(
function.FunctionValue(points, dists)
self['implicit_distance'] = pyvista.convert_array(dists)
# run the clip
result = DataSetFilters._clip_with_function(
return DataSetFilters._clip_with_function(
self,
function,
invert=invert,
value=value,
progress_bar=progress_bar,
crinkle=crinkle,
)
return result

def slice_implicit(
self, implicit_function, generate_triangles=False, contour=False, progress_bar=False
Expand Down Expand Up @@ -4383,8 +4382,7 @@ def sample_over_line(self, pointa, pointb, resolution=None, tolerance=None, prog
resolution = int(self.n_cells)
# Make a line and sample the dataset
line = pyvista.Line(pointa, pointb, resolution=resolution)
sampled_line = line.sample(self, tolerance=tolerance, progress_bar=progress_bar)
return sampled_line
return line.sample(self, tolerance=tolerance, progress_bar=progress_bar)

def plot_over_line(
self,
Expand Down Expand Up @@ -4538,10 +4536,7 @@ def sample_over_multiple_lines(self, points, tolerance=None, progress_bar=False)
"""
# Make a multiple lines and sample the dataset
multiple_lines = pyvista.MultipleLines(points=points)
sampled_multiple_lines = multiple_lines.sample(
self, tolerance=tolerance, progress_bar=progress_bar
)
return sampled_multiple_lines
return multiple_lines.sample(self, tolerance=tolerance, progress_bar=progress_bar)

def sample_over_circular_arc(
self, pointa, pointb, center, resolution=None, tolerance=None, progress_bar=False
Expand Down Expand Up @@ -4614,10 +4609,7 @@ def sample_over_circular_arc(
resolution = int(self.n_cells)
# Make a circular arc and sample the dataset
circular_arc = pyvista.CircularArc(pointa, pointb, center, resolution=resolution)
sampled_circular_arc = circular_arc.sample(
self, tolerance=tolerance, progress_bar=progress_bar
)
return sampled_circular_arc
return circular_arc.sample(self, tolerance=tolerance, progress_bar=progress_bar)

def sample_over_circular_arc_normal(
self,
Expand Down Expand Up @@ -5805,8 +5797,7 @@ def tessellate(self, max_n_subdivide=3, merge_points=True, progress_bar=False):
alg.SetMergePoints(merge_points)
alg.SetMaximumNumberOfSubdivisions(max_n_subdivide)
_update_alg(alg, progress_bar, 'Tessellating Mesh')
output = _get_output(alg)
return output
return _get_output(alg)

def transform(
self: _vtk.vtkDataSet,
Expand Down
6 changes: 2 additions & 4 deletions pyvista/core/filters/poly_data.py
Expand Up @@ -343,8 +343,7 @@ def __iadd__(self, dataset):
so the in-place merge attempt will raise.

"""
merged = self.merge(dataset, inplace=True)
return merged
return self.merge(dataset, inplace=True)

def append_polydata(
self,
Expand Down Expand Up @@ -3726,5 +3725,4 @@ def reconstruct_surface(self, nbr_sz=None, sample_spacing=None, progress_bar=Fal
mc.SetInputConnection(alg.GetOutputPort())
mc.SetValue(0, 0.0)
_update_alg(mc, progress_bar, 'Reconstructing surface')
surf = wrap(mc.GetOutput())
return surf
return wrap(mc.GetOutput())
3 changes: 1 addition & 2 deletions pyvista/core/grid.py
Expand Up @@ -838,11 +838,10 @@ def cast_to_rectilinear_grid(self) -> 'RectilinearGrid':
"""

def gen_coords(i): # numpydoc ignore=GL08
coords = (
return (
np.cumsum(np.insert(np.full(self.dimensions[i] - 1, self.spacing[i]), 0, 0))
+ self.origin[i]
)
return coords

xcoords = gen_coords(0)
ycoords = gen_coords(1)
Expand Down
2 changes: 1 addition & 1 deletion pyvista/core/utilities/arrays.py
Expand Up @@ -203,7 +203,7 @@ def convert_array(arr, name=None, deep=False, array_type=None):

"""
if arr is None:
return
return None
if isinstance(arr, (list, tuple, str)):
arr = np.array(arr)
if isinstance(arr, np.ndarray):
Expand Down
3 changes: 1 addition & 2 deletions pyvista/core/utilities/features.py
Expand Up @@ -95,8 +95,7 @@ def voxelize(mesh, density=None, check_surface=True):
mask = selection.point_data['SelectedPoints'].view(np.bool_)

# extract cells from point indices
vox = ugrid.extract_points(mask)
return vox
return ugrid.extract_points(mask)


def voxelize_volume(mesh, density=None, check_surface=True):
Expand Down
3 changes: 1 addition & 2 deletions pyvista/core/utilities/geometric_sources.py
Expand Up @@ -1305,11 +1305,10 @@ def point_dtype(self) -> str:
It must be either 'float32' or 'float64'.
"""
precision = self.GetOutputPointsPrecision()
point_dtype = {
return {
SINGLE_PRECISION: 'float32',
DOUBLE_PRECISION: 'float64',
}[precision]
return point_dtype

@point_dtype.setter
def point_dtype(self, point_dtype: str):
Expand Down
2 changes: 1 addition & 1 deletion pyvista/core/utilities/helpers.py
Expand Up @@ -142,7 +142,7 @@ def wrap(
return pyvista._wrappers[key](dataset)
except KeyError:
raise TypeError(f'VTK data type ({key}) is not currently supported by pyvista.')
return
return None
tkoyama010 marked this conversation as resolved.
Show resolved Hide resolved

# wrap meshio
if is_meshio_mesh(dataset):
Expand Down
1 change: 1 addition & 0 deletions pyvista/core/utilities/transformations.py
Expand Up @@ -304,6 +304,7 @@ def apply_transformation_to_points(transformation, points, inplace=False):
# If inplace, set the points
if inplace:
points[:] = points_2
return None
else:
# otherwise return the new points
return points_2
6 changes: 2 additions & 4 deletions pyvista/examples/examples.py
Expand Up @@ -199,8 +199,7 @@ def load_globe():
>>> dataset.plot(texture=texture)

"""
globe = pyvista.PolyData(globefile)
return globe
return pyvista.PolyData(globefile)


def load_globe_texture():
Expand Down Expand Up @@ -392,8 +391,7 @@ def load_explicit_structured(dimensions=(5, 6, 7), spacing=(20, 10, 1)):
corners = np.stack((xcorn, ycorn, zcorn))
corners = corners.transpose()

grid = pyvista.ExplicitStructuredGrid(dimensions, corners)
return grid
return pyvista.ExplicitStructuredGrid(dimensions, corners)


def load_nut():
Expand Down