mirror of
				https://github.com/astral-sh/ruff.git
				synced 2025-11-03 21:24:29 +00:00 
			
		
		
		
	If there is any `ParenthesizedWhitespace` (in the sense of LibCST) after the function name `sorted` and before the arguments, then we must wrap `sorted` with parentheses after removing the surrounding function. Closes #15789
		
			
				
	
	
		
			29 lines
		
	
	
	
		
			875 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
	
		
			875 B
		
	
	
	
		
			Python
		
	
	
	
	
	
x = [2, 3, 1]
 | 
						|
list(x)
 | 
						|
list(sorted(x))
 | 
						|
reversed(sorted(x))
 | 
						|
reversed(sorted(x, key=lambda e: e))
 | 
						|
reversed(sorted(x, reverse=True))
 | 
						|
reversed(sorted(x, key=lambda e: e, reverse=True))
 | 
						|
reversed(sorted(x, reverse=True, key=lambda e: e))
 | 
						|
reversed(sorted(x, reverse=False))
 | 
						|
reversed(sorted(x, reverse=x))
 | 
						|
reversed(sorted(x, reverse=not x))
 | 
						|
 | 
						|
# Regression test for: https://github.com/astral-sh/ruff/issues/7289
 | 
						|
reversed(sorted(i for i in range(42)))
 | 
						|
reversed(sorted((i for i in range(42)), reverse=True))
 | 
						|
 | 
						|
# Regression test for: https://github.com/astral-sh/ruff/issues/10335
 | 
						|
reversed(sorted([1, 2, 3], reverse=False or True))
 | 
						|
reversed(sorted([1, 2, 3], reverse=(False or True)))
 | 
						|
 | 
						|
# These fixes need to be parenthesized to avoid syntax errors and behavior
 | 
						|
# changes.
 | 
						|
# See https://github.com/astral-sh/ruff/issues/15789
 | 
						|
reversed(sorted
 | 
						|
(""))
 | 
						|
list(sorted
 | 
						|
    (""))
 | 
						|
list(sorted
 | 
						|
("xy"))
 |