mirror of
				https://github.com/astral-sh/ruff.git
				synced 2025-10-31 20:08:19 +00:00 
			
		
		
		
	[pyupgrade] Make example error out-of-the-box (UP040) (#19296)
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				CI / Determine changes (push) Has been cancelled
				
			
		
			
				
	
				CI / cargo fmt (push) Has been cancelled
				
			
		
			
				
	
				CI / cargo build (release) (push) Has been cancelled
				
			
		
			
				
	
				CI / mkdocs (push) Has been cancelled
				
			
		
			
				
	
				CI / python package (push) Has been cancelled
				
			
		
			
				
	
				CI / pre-commit (push) Has been cancelled
				
			
		
			
				
	
				CI / cargo clippy (push) Has been cancelled
				
			
		
			
				
	
				CI / cargo test (linux) (push) Has been cancelled
				
			
		
			
				
	
				CI / cargo test (linux, release) (push) Has been cancelled
				
			
		
			
				
	
				CI / cargo test (windows) (push) Has been cancelled
				
			
		
			
				
	
				CI / cargo test (wasm) (push) Has been cancelled
				
			
		
			
				
	
				CI / cargo build (msrv) (push) Has been cancelled
				
			
		
			
				
	
				CI / cargo fuzz build (push) Has been cancelled
				
			
		
			
				
	
				CI / fuzz parser (push) Has been cancelled
				
			
		
			
				
	
				CI / test scripts (push) Has been cancelled
				
			
		
			
				
	
				CI / ecosystem (push) Has been cancelled
				
			
		
			
				
	
				CI / Fuzz for new ty panics (push) Has been cancelled
				
			
		
			
				
	
				CI / cargo shear (push) Has been cancelled
				
			
		
			
				
	
				CI / formatter instabilities and black similarity (push) Has been cancelled
				
			
		
			
				
	
				CI / test ruff-lsp (push) Has been cancelled
				
			
		
			
				
	
				CI / check playground (push) Has been cancelled
				
			
		
			
				
	
				CI / benchmarks-instrumented (push) Has been cancelled
				
			
		
			
				
	
				CI / benchmarks-walltime (push) Has been cancelled
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	CI / Determine changes (push) Has been cancelled
				
			CI / cargo fmt (push) Has been cancelled
				
			CI / cargo build (release) (push) Has been cancelled
				
			CI / mkdocs (push) Has been cancelled
				
			CI / python package (push) Has been cancelled
				
			CI / pre-commit (push) Has been cancelled
				
			CI / cargo clippy (push) Has been cancelled
				
			CI / cargo test (linux) (push) Has been cancelled
				
			CI / cargo test (linux, release) (push) Has been cancelled
				
			CI / cargo test (windows) (push) Has been cancelled
				
			CI / cargo test (wasm) (push) Has been cancelled
				
			CI / cargo build (msrv) (push) Has been cancelled
				
			CI / cargo fuzz build (push) Has been cancelled
				
			CI / fuzz parser (push) Has been cancelled
				
			CI / test scripts (push) Has been cancelled
				
			CI / ecosystem (push) Has been cancelled
				
			CI / Fuzz for new ty panics (push) Has been cancelled
				
			CI / cargo shear (push) Has been cancelled
				
			CI / formatter instabilities and black similarity (push) Has been cancelled
				
			CI / test ruff-lsp (push) Has been cancelled
				
			CI / check playground (push) Has been cancelled
				
			CI / benchmarks-instrumented (push) Has been cancelled
				
			CI / benchmarks-walltime (push) Has been cancelled
				
			<!-- Thank you for contributing to Ruff/ty! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? (Please prefix with `[ty]` for ty pull requests.) - Does this pull request include references to any relevant issues? --> ## Summary <!-- What's the purpose of the change? What does it do, and why? --> Part of #18972 This PR makes [non-pep695-type-alias (UP040)](https://docs.astral.sh/ruff/rules/non-pep695-type-alias/#non-pep695-type-alias-up040)'s example error out-of-the-box. [Old example](https://play.ruff.rs/6beca1be-45cd-4e5a-aafa-6a0584c10d64) ```py ListOfInt: TypeAlias = list[int] PositiveInt = TypeAliasType("PositiveInt", Annotated[int, Gt(0)]) ``` [New example](https://play.ruff.rs/bbad34da-bf07-44e6-9f34-53337e8f57d4) ```py from typing import Annotated, TypeAlias, TypeAliasType from annotated_types import Gt ListOfInt: TypeAlias = list[int] PositiveInt = TypeAliasType("PositiveInt", Annotated[int, Gt(0)]) ``` Imports were also added to the "Use instead" section. ## Test Plan <!-- How was it tested? --> N/A, no functionality/tests affected
This commit is contained in:
		
							parent
							
								
									4bc27133a9
								
							
						
					
					
						commit
						dca594f89f
					
				
					 1 changed files with 6 additions and 0 deletions
				
			
		|  | @ -40,12 +40,18 @@ use super::{ | ||||||
| ///
 | ///
 | ||||||
| /// ## Example
 | /// ## Example
 | ||||||
| /// ```python
 | /// ```python
 | ||||||
|  | /// from typing import Annotated, TypeAlias, TypeAliasType
 | ||||||
|  | /// from annotated_types import Gt
 | ||||||
|  | ///
 | ||||||
| /// ListOfInt: TypeAlias = list[int]
 | /// ListOfInt: TypeAlias = list[int]
 | ||||||
| /// PositiveInt = TypeAliasType("PositiveInt", Annotated[int, Gt(0)])
 | /// PositiveInt = TypeAliasType("PositiveInt", Annotated[int, Gt(0)])
 | ||||||
| /// ```
 | /// ```
 | ||||||
| ///
 | ///
 | ||||||
| /// Use instead:
 | /// Use instead:
 | ||||||
| /// ```python
 | /// ```python
 | ||||||
|  | /// from typing import Annotated
 | ||||||
|  | /// from annotated_types import Gt
 | ||||||
|  | ///
 | ||||||
| /// type ListOfInt = list[int]
 | /// type ListOfInt = list[int]
 | ||||||
| /// type PositiveInt = Annotated[int, Gt(0)]
 | /// type PositiveInt = Annotated[int, Gt(0)]
 | ||||||
| /// ```
 | /// ```
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 GiGaGon
						GiGaGon