Fix identity comparisons with literals and mutable default arguments#1350
Open
dhruvildarji wants to merge 1 commit intoAtsushiSakai:masterfrom
Open
Fix identity comparisons with literals and mutable default arguments#1350dhruvildarji wants to merge 1 commit intoAtsushiSakai:masterfrom
dhruvildarji wants to merge 1 commit intoAtsushiSakai:masterfrom
Conversation
Replace `is`/`is not` comparisons with non-None literals (`==`/`!=`/`not`) to fix SyntaxWarning in Python 3.12+ (related to AtsushiSakai#1291). Also replace mutable default arguments (lists) with None or tuples to prevent shared state bugs. Identity comparisons fixed: - `is not self.n_links` (integer) in 3 arm navigation files - `state is WAIT_FOR_NEW_GOAL` (integer) in n_joint_arm_to_point_control.py - `path_found is False` (bool literal) in probabilistic_road_map.py - `flag is inside` (bool) in grid_map_lib.py Mutable default arguments fixed: - `obstacles=[]` -> `obstacles=None` in arm_obstacle_navigation.py and _2.py - `start_vel=[0,0,0]` etc. -> tuples in TrajectoryGenerator.py - `obstacle_avoid_points=[]` -> `None` in GridWithDynamicObstacles.py - Removed mutable class-level list defaults in Grid class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
is/is notcomparisons with non-None literals to use==/!=/notinstead, fixingSyntaxWarningin Python 3.12+ (these will becomeSyntaxErrorin a future Python version)Noneor tuples to prevent shared-state bugsChanges
Identity comparisons fixed (9 instances across 6 files)
Using
is/is notto compare with integers, booleans, or other non-singleton literals is deprecated in Python 3.12+ and emitsSyntaxWarning. This is relevant to #1291 (Python 3.14 support).NLinkArm.py,arm_obstacle_navigation.py,arm_obstacle_navigation_2.pyi is not self.n_links->i != self.n_links(integer comparison)n_joint_arm_to_point_control.pystate is WAIT_FOR_NEW_GOAL/state is MOVING_TO_GOAL->==(integer comparison)probabilistic_road_map.pypath_found is False->not path_foundgrid_map_lib.pyflag is inside->flag == inside(boolean comparison)Mutable default arguments fixed (4 files)
Mutable default arguments are a well-known Python pitfall -- the default object is shared across all calls, so mutations persist unexpectedly.
arm_obstacle_navigation.py,arm_obstacle_navigation_2.pyobstacles=[]->obstacles=Nonewith guardTrajectoryGenerator.pystart_vel=[0,0,0]etc. -> tuples(0,0,0)(immutable, only indexed)GridWithDynamicObstacles.pyobstacle_avoid_points=[]->Nonewith guard; removed mutable class-level list defaultsTest plan
-Werrorflag used in CI test runner