mirror of
				https://github.com/astral-sh/ruff.git
				synced 2025-10-29 19:17:20 +00:00 
			
		
		
		
	[flake8-comprehensions] Preserve trailing commas for single-element lists (C409) (#19571)
	
		
			
	
		
	
	
		
	
		
			Some checks are pending
		
		
	
	
		
			
				
	
				CI / Determine changes (push) Waiting to run
				
			
		
			
				
	
				CI / cargo fmt (push) Waiting to run
				
			
		
			
				
	
				CI / cargo clippy (push) Blocked by required conditions
				
			
		
			
				
	
				CI / cargo test (linux) (push) Blocked by required conditions
				
			
		
			
				
	
				CI / cargo test (linux, release) (push) Blocked by required conditions
				
			
		
			
				
	
				CI / cargo test (windows) (push) Blocked by required conditions
				
			
		
			
				
	
				CI / cargo test (wasm) (push) Blocked by required conditions
				
			
		
			
				
	
				CI / cargo build (release) (push) Waiting to run
				
			
		
			
				
	
				CI / mkdocs (push) Waiting to run
				
			
		
			
				
	
				CI / cargo build (msrv) (push) Blocked by required conditions
				
			
		
			
				
	
				CI / cargo fuzz build (push) Blocked by required conditions
				
			
		
			
				
	
				CI / fuzz parser (push) Blocked by required conditions
				
			
		
			
				
	
				CI / test scripts (push) Blocked by required conditions
				
			
		
			
				
	
				CI / ecosystem (push) Blocked by required conditions
				
			
		
			
				
	
				CI / Fuzz for new ty panics (push) Blocked by required conditions
				
			
		
			
				
	
				CI / cargo shear (push) Blocked by required conditions
				
			
		
			
				
	
				CI / python package (push) Waiting to run
				
			
		
			
				
	
				CI / pre-commit (push) Waiting to run
				
			
		
			
				
	
				CI / formatter instabilities and black similarity (push) Blocked by required conditions
				
			
		
			
				
	
				CI / test ruff-lsp (push) Blocked by required conditions
				
			
		
			
				
	
				CI / check playground (push) Blocked by required conditions
				
			
		
			
				
	
				CI / benchmarks instrumented (ruff) (push) Blocked by required conditions
				
			
		
			
				
	
				CI / benchmarks instrumented (ty) (push) Blocked by required conditions
				
			
		
			
				
	
				CI / benchmarks-walltime (push) Blocked by required conditions
				
			
		
			
				
	
				[ty Playground] Release / publish (push) Waiting to run
				
			
		
		
	
	
				
					
				
			
		
			Some checks are pending
		
		
	
	CI / Determine changes (push) Waiting to run
				
			CI / cargo fmt (push) Waiting to run
				
			CI / cargo clippy (push) Blocked by required conditions
				
			CI / cargo test (linux) (push) Blocked by required conditions
				
			CI / cargo test (linux, release) (push) Blocked by required conditions
				
			CI / cargo test (windows) (push) Blocked by required conditions
				
			CI / cargo test (wasm) (push) Blocked by required conditions
				
			CI / cargo build (release) (push) Waiting to run
				
			CI / mkdocs (push) Waiting to run
				
			CI / cargo build (msrv) (push) Blocked by required conditions
				
			CI / cargo fuzz build (push) Blocked by required conditions
				
			CI / fuzz parser (push) Blocked by required conditions
				
			CI / test scripts (push) Blocked by required conditions
				
			CI / ecosystem (push) Blocked by required conditions
				
			CI / Fuzz for new ty panics (push) Blocked by required conditions
				
			CI / cargo shear (push) Blocked by required conditions
				
			CI / python package (push) Waiting to run
				
			CI / pre-commit (push) Waiting to run
				
			CI / formatter instabilities and black similarity (push) Blocked by required conditions
				
			CI / test ruff-lsp (push) Blocked by required conditions
				
			CI / check playground (push) Blocked by required conditions
				
			CI / benchmarks instrumented (ruff) (push) Blocked by required conditions
				
			CI / benchmarks instrumented (ty) (push) Blocked by required conditions
				
			CI / benchmarks-walltime (push) Blocked by required conditions
				
			[ty Playground] Release / publish (push) Waiting to run
				
			## Summary Fixes #19568
This commit is contained in:
		
							parent
							
								
									b5a3503a58
								
							
						
					
					
						commit
						c0fb235a70
					
				
					 4 changed files with 70 additions and 1 deletions
				
			
		|  | @ -42,3 +42,6 @@ tuple( | |||
|         x for x in [1,2,3] | ||||
|     } | ||||
| ) | ||||
| 
 | ||||
| t9 = tuple([1],) | ||||
| t10 = tuple([1, 2],) | ||||
|  |  | |||
|  | @ -124,7 +124,7 @@ pub(crate) fn unnecessary_literal_within_tuple_call( | |||
|                 let needs_trailing_comma = if let [item] = elts.as_slice() { | ||||
|                     SimpleTokenizer::new( | ||||
|                         checker.locator().contents(), | ||||
|                         TextRange::new(item.end(), call.end()), | ||||
|                         TextRange::new(item.end(), argument.end()), | ||||
|                     ) | ||||
|                     .all(|token| token.kind != SimpleTokenKind::Comma) | ||||
|                 } else { | ||||
|  |  | |||
|  | @ -247,3 +247,36 @@ help: Rewrite as a tuple literal | |||
| 28 | tuple([x for x in range(5)]) | ||||
| 29 | tuple({x for x in range(10)}) | ||||
| note: This is an unsafe fix and may change runtime behavior | ||||
| 
 | ||||
| C409 [*] Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal) | ||||
|   --> C409.py:46:6 | ||||
|    | | ||||
| 44 | ) | ||||
| 45 | | ||||
| 46 | t9 = tuple([1],) | ||||
|    |      ^^^^^^^^^^^ | ||||
| 47 | t10 = tuple([1, 2],) | ||||
|    | | ||||
| help: Rewrite as a tuple literal | ||||
| 43 |     } | ||||
| 44 | ) | ||||
| 45 |  | ||||
|    - t9 = tuple([1],) | ||||
| 46 + t9 = (1,) | ||||
| 47 | t10 = tuple([1, 2],) | ||||
| note: This is an unsafe fix and may change runtime behavior | ||||
| 
 | ||||
| C409 [*] Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal) | ||||
|   --> C409.py:47:7 | ||||
|    | | ||||
| 46 | t9 = tuple([1],) | ||||
| 47 | t10 = tuple([1, 2],) | ||||
|    |       ^^^^^^^^^^^^^^ | ||||
|    | | ||||
| help: Rewrite as a tuple literal | ||||
| 44 | ) | ||||
| 45 |  | ||||
| 46 | t9 = tuple([1],) | ||||
|    - t10 = tuple([1, 2],) | ||||
| 47 + t10 = (1, 2) | ||||
| note: This is an unsafe fix and may change runtime behavior | ||||
|  |  | |||
|  | @ -344,3 +344,36 @@ help: Rewrite as a generator | |||
| 42 |         x for x in [1,2,3] | ||||
| 43 |     } | ||||
| note: This is an unsafe fix and may change runtime behavior | ||||
| 
 | ||||
| C409 [*] Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal) | ||||
|   --> C409.py:46:6 | ||||
|    | | ||||
| 44 | ) | ||||
| 45 | | ||||
| 46 | t9 = tuple([1],) | ||||
|    |      ^^^^^^^^^^^ | ||||
| 47 | t10 = tuple([1, 2],) | ||||
|    | | ||||
| help: Rewrite as a tuple literal | ||||
| 43 |     } | ||||
| 44 | ) | ||||
| 45 |  | ||||
|    - t9 = tuple([1],) | ||||
| 46 + t9 = (1,) | ||||
| 47 | t10 = tuple([1, 2],) | ||||
| note: This is an unsafe fix and may change runtime behavior | ||||
| 
 | ||||
| C409 [*] Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal) | ||||
|   --> C409.py:47:7 | ||||
|    | | ||||
| 46 | t9 = tuple([1],) | ||||
| 47 | t10 = tuple([1, 2],) | ||||
|    |       ^^^^^^^^^^^^^^ | ||||
|    | | ||||
| help: Rewrite as a tuple literal | ||||
| 44 | ) | ||||
| 45 |  | ||||
| 46 | t9 = tuple([1],) | ||||
|    - t10 = tuple([1, 2],) | ||||
| 47 + t10 = (1, 2) | ||||
| note: This is an unsafe fix and may change runtime behavior | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Parizher
						Dan Parizher