Skip to content

Enable strict=True for zip() where safe #4547

Open
Oll-iver wants to merge 25 commits intoManimCommunity:mainfrom
Oll-iver:strict-zip-fix
Open

Enable strict=True for zip() where safe #4547
Oll-iver wants to merge 25 commits intoManimCommunity:mainfrom
Oll-iver:strict-zip-fix

Conversation

@Oll-iver
Copy link

Overview: What does this pull request change?

Changed uses of zip() to strict=True where iterables are guaranteed or expected to be of equal length including test suite.
Explicitly set strict=False where it had not already been set and truncation is intended.
All remaining uses of strict=False are instances where the zip() function takes iterables that are not guaranteed or always expected to be of equal length; for example columns and colours in matrix.py.

Motivation and Explanation: Why and how do your changes improve the library?

This PR addresses the cleanup task described in Issue #4521.
Future bugs will now raise a ValueError rather than silently proceeding, producing unexpected results, or crashing elsewhere.
Some tests were actually ineffective without strict=True as they worked by checking the output of zip() was the same length as its inputs.

Links to added or changed documentation pages

Further Information and Comments

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

…tuple has a corresponding datapoint in the second (ie same length)
…rs and forces rgbas and offset to be the same size for strict=True
…rs or strictly forced to be the same length (n). In any case they'll always be the same length so strict=True works.
…us_list is defined directly from the length of vertex_group; both outer_vertices and inner_vertices posess n vertices.
…e; labels and parts are seemingly user inputs with no guarantee of equal length; val_range is defined to be same lenght as self.bar_names; however there's no authentication that self.values has a fixed length after it's been defined ie user can append to the list creating a mismatch between len(self.values) and len(self.bars)
…h or manipulated to be by the align_data function. In the match_points function there is currently no validation to ensure both mobjects are the same length.
to strict=False due to failing test cases
…in _add_x_axis_labels we define val_range to be the same length as self.bar_names
… in the zip() function are of the same length. Every other time zip() is used here it is generally immediately manipulating or explicitly defining the tuples to be of same length
…r manipulated to be the same size using the make_even function.
… second tuple is simply a cyclic shift of the first.
…attrs so they are guaranteed to have equal lengths.
…o be equal size or defined to be equal size.
…h tuples as current_number_of_curves is read directly from the shape of bezier_tuples and is used to dictate the size of split_factors.
…th tuples as floors is defined directly from alphas (which also defines alphas_mod1)
…o strict=True. While it is technically possible to pass tuples to this function that are *not* the same length, this would result in generally unexpected behaviour anyway.
…bels is dependent on tick_range so guaranteed to have the same length.
…have axis manipulated to be the same length as tick_range. In get_riemann_rectangles() we have colors dependent on of x_range_Array forcing them to be the same length. Finally in plot_line_graph() it is clearly intended that all inputs used in the zip() function are of the same length (except possibly z which may not exist and will be made equal length to x); while it is not guaranteed they will be the same length this would cause unintended behaviour.
…ost test cases either a) hardcode two things to be the same length, b) verify things are the same length before the function or c) explicitly exist to check whether two things are the same length.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant