mirror of
				https://github.com/astral-sh/ruff.git
				synced 2025-10-29 19:17:20 +00:00 
			
		
		
		
	 62c7d8f6ba
			
		
	
	
		62c7d8f6ba
		
			
		
	
	
	
	
		
			
			## Summary This PR adds support for control flow for match statement. It also adds the necessary infrastructure required for narrowing constraints in case blocks and implements the logic for `PatternMatchSingleton` which is either `None` / `True` / `False`. Even after this the inferred type doesn't get simplified completely, there's a TODO for that in the test code. ## Test Plan Add test cases for control flow for (a) when there's a wildcard pattern and (b) when there isn't. There's also a test case to verify the narrowing logic. --------- Co-authored-by: Carl Meyer <carl@astral.sh>
		
			
				
	
	
		
			16 lines
		
	
	
	
		
			377 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			16 lines
		
	
	
	
		
			377 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
| use ruff_python_parser::parse_module;
 | |
| 
 | |
| #[test]
 | |
| fn pattern_is_wildcard() {
 | |
|     let source_code = r"
 | |
| match subject:
 | |
|     case _ as x: ...
 | |
|     case _ | _: ...
 | |
|     case _: ...
 | |
| ";
 | |
|     let parsed = parse_module(source_code).unwrap();
 | |
|     let cases = &parsed.syntax().body[0].as_match_stmt().unwrap().cases;
 | |
|     for case in cases {
 | |
|         assert!(case.pattern.is_wildcard());
 | |
|     }
 | |
| }
 |