mirror of
				https://github.com/astral-sh/ruff.git
				synced 2025-10-31 12:05:57 +00:00 
			
		
		
		
	 1968332d93
			
		
	
	
		1968332d93
		
	
	
	
	
		
			
			## Summary
This rule removes `PLR1701` and redirects it to `SIM101`.
In addition to that, the `SIM101` autofix has been fixed to add padding
if required.
### `PLR1701` has bugs
It also seems that the implementation of `PLR1701` is incorrect in
multiple scenarios. For example, the following code snippet:
```py
# There are two _different_ variables `a` and `b`
if isinstance(a, int) or isinstance(b, bool) or isinstance(a, float):
    pass
# There's another condition `or 1`
if isinstance(self.k, int) or isinstance(self.k, float) or 1:
    pass
```
is fixed to:
```py
# Fixed to only considering variable `a`
if isinstance(a, (float, int)):
    pass
# The additional condition is not present in the fix
if isinstance(self.k, (float, int)):
    pass
```
Playground: https://play.ruff.rs/6cfbdfb7-f183-43b0-b59e-31e728b34190
## Documentation Preview
### `PLR1701`
<img width="1397" alt="Screenshot 2024-06-25 at 11 14 40"
src="779ee84d-7c4d-4bb8-a3a4-c2b23a313eba">
## Test Plan
Remove the test cases for `PLR1701`, port the padding test case to
`SIM101` and update the snapshot.
		
	
			
		
			
				
	
	
		
			54 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| if isinstance(a, int) or isinstance(a, float):  # SIM101
 | |
|     pass
 | |
| 
 | |
| if isinstance(a, (int, float)) or isinstance(a, bool):  # SIM101
 | |
|     pass
 | |
| 
 | |
| if isinstance(a, int) or isinstance(a, float) or isinstance(b, bool):  # SIM101
 | |
|     pass
 | |
| 
 | |
| if isinstance(b, bool) or isinstance(a, int) or isinstance(a, float):  # SIM101
 | |
|     pass
 | |
| 
 | |
| if isinstance(a, int) or isinstance(b, bool) or isinstance(a, float):  # SIM101
 | |
|     pass
 | |
| 
 | |
| if (isinstance(a, int) or isinstance(a, float)) and isinstance(b, bool):  # SIM101
 | |
|     pass
 | |
| 
 | |
| if isinstance(a.b, int) or isinstance(a.b, float):  # SIM101
 | |
|     pass
 | |
| 
 | |
| if isinstance(a(), int) or isinstance(a(), float):  # SIM101
 | |
|     pass
 | |
| 
 | |
| if isinstance(a, int) and isinstance(b, bool) or isinstance(a, float):
 | |
|     pass
 | |
| 
 | |
| if isinstance(a, bool) or isinstance(b, str):
 | |
|     pass
 | |
| 
 | |
| if isinstance(a, int) or isinstance(a.b, float):
 | |
|     pass
 | |
| 
 | |
| # OK
 | |
| if isinstance(a, int) or unrelated_condition or isinstance(a, float):
 | |
|     pass
 | |
| 
 | |
| if x or isinstance(a, int) or isinstance(a, float):
 | |
|     pass
 | |
| 
 | |
| if x or y or isinstance(a, int) or isinstance(a, float) or z:
 | |
|     pass
 | |
| 
 | |
| def f():
 | |
|     # OK
 | |
|     def isinstance(a, b):
 | |
|         return False
 | |
| 
 | |
|     if isinstance(a, int) or isinstance(a, float):
 | |
|         pass
 | |
| 
 | |
| # Regression test for: https://github.com/astral-sh/ruff/issues/7455#issuecomment-1722460483
 | |
| if(isinstance(a, int)) or (isinstance(a, float)):
 | |
|     pass
 |