| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Good digging, there! Wow, yeah, we need to refactor this piece of code :) |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
I tried long and hard to see if there was a sane way of annotating the output field of the Block class. In the end I concluded that, from a typing perspective, the current code is somewhat insane, so there's no sane way of doing it without substantially refactoring the code first 🙃 For now, I propose that we annotate it with Any and leave it for another day.
The issue is that output usually has type str | None, as stated by the docstring here:
cpython/Tools/clinic/clinic.py
Lines 1659 to 1660 in 363f4f9
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
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
cpython/Tools/clinic/clinic.py
Lines 4515 to 4518 in 363f4f9
Needless to say, this makes mypy furious if you give Block.output a type that isn't Any 🙃