Title: gh-118761: Improve import time of ``annotationlib`` by DavidCEllis · Pull Request #132028 · python/cpython · GitHub
Open Graph Title: gh-118761: Improve import time of ``annotationlib`` by DavidCEllis · Pull Request #132028 · python/cpython
X Title: gh-118761: Improve import time of ``annotationlib`` by DavidCEllis · Pull Request #132028 · python/cpython
Description: This PR converts annotationlib.py into a package with annotationlib/__init__.py and annotationlib/_stringifier.py. Discussed here: https://discuss.python.org/t/pep-749-implementing-pep-649/54974/63 This is done in order to move the definition of _Stringifier into a new submodule in order to defer the import of ast in the main module. The outcome of this is that ast should only be imported if any of the following occur: get_annotations(obj, format=Format.STRING)1 is used and the output is not an empty dict get_annotations(obj, format=Format.FORWARDREF) is used and there are actually forward references forwardref.__forward_arg__ is called and forwardref.__ast_node__ is not None Note: I've used a class with a __getattr__ method as a way of deferring imports in the current PR but I'd be happy to change that to something else if there's a more standard pattern. My machine isn't a super stable benchmarking machine so take these only as rough estimates (they're slightly different to those posted in the discuss thread as it's a different run). This branch: import time: self [us] | cumulative | imported package ... import time: 688 | 688 | types import time: 3373 | 4061 | enum import time: 306 | 306 | keyword import time: 906 | 5272 | annotationlib Main: import time: self [us] | cumulative | imported package ... import time: 4032 | 4032 | _ast import time: 1605 | 5637 | ast import time: 432 | 432 | types import time: 2027 | 2459 | enum import time: 126 | 126 | itertools import time: 205 | 205 | keyword import time: 77 | 77 | _operator import time: 341 | 418 | operator import time: 210 | 210 | reprlib import time: 357 | 357 | _collections import time: 1415 | 2729 | collections import time: 217 | 217 | _functools import time: 1396 | 4341 | functools import time: 2198 | 14634 | annotationlib Issue: gh-118761 Footnotes or any of the similar methods such as call_annotate_function ↩
Open Graph Description: This PR converts annotationlib.py into a package with annotationlib/__init__.py and annotationlib/_stringifier.py. Discussed here: https://discuss.python.org/t/pep-749-implementing-pep-649/54974/6...
X Description: This PR converts annotationlib.py into a package with annotationlib/__init__.py and annotationlib/_stringifier.py. Discussed here: https://discuss.python.org/t/pep-749-implementing-pep-649/54974/6...
Opengraph URL: https://github.com/python/cpython/pull/132028
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:5e352553-5043-0814-2aa0-fc37af78395c |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 90B8:26866E:31320:447B0:6969F8EF |
| html-safe-nonce | 32d2eaf9e69c3bcbbcb5aeb94f3fd32922533e8c4a702370906f4bad91cd2d37 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MEI4OjI2ODY2RTozMTMyMDo0NDdCMDo2OTY5RjhFRiIsInZpc2l0b3JfaWQiOiI4MDM1MTEwMjAzMDc1MTk3MTY3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 4da117ce441008d0b39bd02008463ea975a279b945b33454ad91eb1942bead73 |
| hovercard-subject-tag | pull_request:2434910696 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/132028/files |
| twitter:image | https://avatars.githubusercontent.com/u/15880420?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/15880420?s=400&v=4 |
| og:image:alt | This PR converts annotationlib.py into a package with annotationlib/__init__.py and annotationlib/_stringifier.py. Discussed here: https://discuss.python.org/t/pep-749-implementing-pep-649/54974/6... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7b32f1c7c4549428ee399213e8345494fc55b5637195d3fc5f493657579235e8 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | bdde15ad1b403e23b08bbd89b53fbe6bdf688cad |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width