GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-104050: Argument Clinic: Annotate the `Block` class by AlexWaygood · Pull Request #106519 · python/cpython Conversation
|
| output is either str or None. If str, it's the output | |
| from this block, with embedded '\n' characters. |
But whenever self.block is referenced from inside the DSLParser class, it's of type list[str] (I'm pretty confident self.block is an instance of Block):
cpython/Tools/clinic/clinic.py
Lines 4471 to 4476 in 363f4f9
| def directive_dump(self, name: str) -> None: | |
| self.block.output.append(self.clinic.get_destination(name).dump()) | |
| def directive_printout(self, *args: str) -> None: | |
| self.block.output.append(' '.join(args)) | |
| self.block.output.append('\n') |
This is because DSLParser.parse() sets block.output to a list at the beginning of the function, and then sets it back to a string at the end of the function:
cpython/Tools/clinic/clinic.py
Line 4502 in 363f4f9
| block.output = [] |
cpython/Tools/clinic/clinic.py
Lines 4515 to 4518 in 363f4f9
| if self.preserve_output: | |
| if block.output: | |
| fail("'preserve' only works for blocks that don't produce any output!") | |
| block.output = self.saved_output |
Needless to say, this makes mypy furious if you give Block.output a type that isn't Any 🙃
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Good digging, there! Wow, yeah, we need to refactor this piece of code :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.