Title: gh-104050: Argument Clinic: Annotate the `Block` class by AlexWaygood · Pull Request #106519 · python/cpython · GitHub
Open Graph Title: gh-104050: Argument Clinic: Annotate the `Block` class by AlexWaygood · Pull Request #106519 · python/cpython
X Title: gh-104050: Argument Clinic: Annotate the `Block` class by AlexWaygood · Pull Request #106519 · python/cpython
Description: 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 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 🙃 Issue: gh-104050
Open Graph Description: 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, ...
X Description: 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, ...
Opengraph URL: https://github.com/python/cpython/pull/106519
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/checks(.:format) |
| route-controller | pull_requests |
| route-action | checks |
| fetch-nonce | v2:f05e620a-f3ec-9b67-5a89-3892269449f8 |
| current-catalog-service-hash | 87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a |
| request-id | ACC8:1069C6:9C6224:D18F46:69697FA4 |
| html-safe-nonce | 821d44bdbe27b68a0a050e4ff137fc9598efef6ed268344915b9c7d87dab4c9f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQ0M4OjEwNjlDNjo5QzYyMjQ6RDE4RjQ2OjY5Njk3RkE0IiwidmlzaXRvcl9pZCI6Ijg5NTI1Mzg3NTgyMTY1MTU0OTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2c84f4e4c514ddc84910d36006bcac644c7f1e29872e30287c66c73bd3a00ec7 |
| hovercard-subject-tag | pull_request:1424848041 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/106519/checks |
| twitter:image | https://avatars.githubusercontent.com/u/66076021?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/66076021?s=400&v=4 |
| og:image:alt | 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, ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | f33e4b94c8824ab2b434d82a94139432fb5ebee9df4b75304140ad22508c4a77 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width full-width-p-0 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 48f380098b30acbb700b04f1724481ca10d574fc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width