mirror of
				https://github.com/astral-sh/ruff.git
				synced 2025-10-31 12:05:57 +00:00 
			
		
		
		
	[ty] use the name span rather than the statement span for unresolved global lints (#19379)
				
					
				
			This is a follow-up to https://github.com/astral-sh/ruff/pull/19344 that improves the error formatting slightly. For example with this program: ```py def f(): global foo, bar ``` Before we printed: ``` 1 | def f(): 2 | global foo, bar | ^^^^^^^^^^^^^^^ `foo` has no declarations or bindings in the global scope ... 1 | def f(): 2 | global foo, bar | ^^^^^^^^^^^^^^^ `bar` has no declarations or bindings in the global scope ``` Now we print: ``` 1 | def f(): 2 | global foo, bar | ^^^ `foo` has no declarations or bindings in the global scope ... 1 | def f(): 2 | global foo, bar | ^^^ `bar` has no declarations or bindings in the global scope ``` --------- Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
		
							parent
							
								
									5f2e855c29
								
							
						
					
					
						commit
						64ac7d7dbf
					
				
					 1 changed files with 2 additions and 2 deletions
				
			
		|  | @ -4672,7 +4672,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { | ||||||
|         // in the global scope.
 |         // in the global scope.
 | ||||||
|         let ast::StmtGlobal { |         let ast::StmtGlobal { | ||||||
|             node_index: _, |             node_index: _, | ||||||
|             range, |             range: _, | ||||||
|             names, |             names, | ||||||
|         } = global; |         } = global; | ||||||
|         let global_place_table = self.index.place_table(FileScopeId::global()); |         let global_place_table = self.index.place_table(FileScopeId::global()); | ||||||
|  | @ -4694,7 +4694,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { | ||||||
|             } |             } | ||||||
|             // This variable isn't explicitly defined in the global scope, nor is it an
 |             // This variable isn't explicitly defined in the global scope, nor is it an
 | ||||||
|             // implicit global from `types.ModuleType`, so we consider this `global` statement invalid.
 |             // implicit global from `types.ModuleType`, so we consider this `global` statement invalid.
 | ||||||
|             let Some(builder) = self.context.report_lint(&UNRESOLVED_GLOBAL, range) else { |             let Some(builder) = self.context.report_lint(&UNRESOLVED_GLOBAL, name) else { | ||||||
|                 return; |                 return; | ||||||
|             }; |             }; | ||||||
|             let mut diag = |             let mut diag = | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jack O'Connor
						Jack O'Connor