mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	gh-104504: Cases generator: enable mypy's possibly-undefined error code (#108454)
				
					
				
			This commit is contained in:
		
							parent
							
								
									6895ddf6cb
								
							
						
					
					
						commit
						5a25daa512
					
				
					 2 changed files with 10 additions and 5 deletions
				
			
		|  | @ -156,6 +156,8 @@ def effect_str(effects: list[StackEffect]) -> str: | ||||||
|             return str(n_effect) |             return str(n_effect) | ||||||
| 
 | 
 | ||||||
|         instr: AnyInstruction | None |         instr: AnyInstruction | None | ||||||
|  |         popped: str | None = None | ||||||
|  |         pushed: str | None = None | ||||||
|         match thing: |         match thing: | ||||||
|             case parsing.InstDef(): |             case parsing.InstDef(): | ||||||
|                 if thing.kind != "op" or self.instrs[thing.name].is_viable_uop(): |                 if thing.kind != "op" or self.instrs[thing.name].is_viable_uop(): | ||||||
|  | @ -173,7 +175,7 @@ def effect_str(effects: list[StackEffect]) -> str: | ||||||
|                 instr = self.pseudo_instrs[thing.name] |                 instr = self.pseudo_instrs[thing.name] | ||||||
|                 # Calculate stack effect, and check that it's the the same |                 # Calculate stack effect, and check that it's the the same | ||||||
|                 # for all targets. |                 # for all targets. | ||||||
|                 for idx, target in enumerate(self.pseudos[thing.name].targets): |                 for target in self.pseudos[thing.name].targets: | ||||||
|                     target_instr = self.instrs.get(target) |                     target_instr = self.instrs.get(target) | ||||||
|                     # Currently target is always an instr. This could change |                     # Currently target is always an instr. This could change | ||||||
|                     # in the future, e.g., if we have a pseudo targetting a |                     # in the future, e.g., if we have a pseudo targetting a | ||||||
|  | @ -181,13 +183,14 @@ def effect_str(effects: list[StackEffect]) -> str: | ||||||
|                     assert target_instr |                     assert target_instr | ||||||
|                     target_popped = effect_str(target_instr.input_effects) |                     target_popped = effect_str(target_instr.input_effects) | ||||||
|                     target_pushed = effect_str(target_instr.output_effects) |                     target_pushed = effect_str(target_instr.output_effects) | ||||||
|                     if idx == 0: |                     if popped is None: | ||||||
|                         popped, pushed = target_popped, target_pushed |                         popped, pushed = target_popped, target_pushed | ||||||
|                     else: |                     else: | ||||||
|                         assert popped == target_popped |                         assert popped == target_popped | ||||||
|                         assert pushed == target_pushed |                         assert pushed == target_pushed | ||||||
|             case _: |             case _: | ||||||
|                 assert_never(thing) |                 assert_never(thing) | ||||||
|  |         assert popped is not None and pushed is not None | ||||||
|         return instr, popped, pushed |         return instr, popped, pushed | ||||||
| 
 | 
 | ||||||
|     @contextlib.contextmanager |     @contextlib.contextmanager | ||||||
|  | @ -376,6 +379,7 @@ def write_metadata(self, metadata_filename: str, pymetadata_filename: str) -> No | ||||||
|         # Compute the set of all instruction formats. |         # Compute the set of all instruction formats. | ||||||
|         all_formats: set[str] = set() |         all_formats: set[str] = set() | ||||||
|         for thing in self.everything: |         for thing in self.everything: | ||||||
|  |             format: str | None = None | ||||||
|             match thing: |             match thing: | ||||||
|                 case OverriddenInstructionPlaceHolder(): |                 case OverriddenInstructionPlaceHolder(): | ||||||
|                     continue |                     continue | ||||||
|  | @ -384,15 +388,16 @@ def write_metadata(self, metadata_filename: str, pymetadata_filename: str) -> No | ||||||
|                 case parsing.Macro(): |                 case parsing.Macro(): | ||||||
|                     format = self.macro_instrs[thing.name].instr_fmt |                     format = self.macro_instrs[thing.name].instr_fmt | ||||||
|                 case parsing.Pseudo(): |                 case parsing.Pseudo(): | ||||||
|                     for idx, target in enumerate(self.pseudos[thing.name].targets): |                     for target in self.pseudos[thing.name].targets: | ||||||
|                         target_instr = self.instrs.get(target) |                         target_instr = self.instrs.get(target) | ||||||
|                         assert target_instr |                         assert target_instr | ||||||
|                         if idx == 0: |                         if format is None: | ||||||
|                             format = target_instr.instr_fmt |                             format = target_instr.instr_fmt | ||||||
|                         else: |                         else: | ||||||
|                             assert format == target_instr.instr_fmt |                             assert format == target_instr.instr_fmt | ||||||
|                 case _: |                 case _: | ||||||
|                     assert_never(thing) |                     assert_never(thing) | ||||||
|  |             assert format is not None | ||||||
|             all_formats.add(format) |             all_formats.add(format) | ||||||
| 
 | 
 | ||||||
|         # Turn it into a sorted list of enum values. |         # Turn it into a sorted list of enum values. | ||||||
|  |  | ||||||
|  | @ -9,5 +9,5 @@ python_version = 3.10 | ||||||
| # ...And be strict: | # ...And be strict: | ||||||
| strict = True | strict = True | ||||||
| strict_concatenate = True | strict_concatenate = True | ||||||
| enable_error_code = ignore-without-code,redundant-expr,truthy-bool | enable_error_code = ignore-without-code,redundant-expr,truthy-bool,possibly-undefined | ||||||
| warn_unreachable = True | warn_unreachable = True | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Alex Waygood
						Alex Waygood