Title: Let function signature hook have context of caller · Issue #14845 · python/mypy · GitHub
Open Graph Title: Let function signature hook have context of caller · Issue #14845 · python/mypy
X Title: Let function signature hook have context of caller · Issue #14845 · python/mypy
Description: When executing (plugin) function signature hooks, actual argument types are not available yet (and, in fact, there's no caller context). In #14526, the signature of attr.evolve(inst, ...) depended on the inst argument, and we had no choi...
Open Graph Description: When executing (plugin) function signature hooks, actual argument types are not available yet (and, in fact, there's no caller context). In #14526, the signature of attr.evolve(inst, ...) depended ...
X Description: When executing (plugin) function signature hooks, actual argument types are not available yet (and, in fact, there's no caller context). In #14526, the signature of attr.evolve(inst, ...) depen...
Opengraph URL: https://github.com/python/mypy/issues/14845
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Let function signature hook have context of caller","articleBody":"When executing (plugin) function signature hooks, actual argument types are not available yet (and, in fact, there's no caller context).\r\n\r\nIn #14526, the signature of `attr.evolve(inst, ...)` depended on the `inst` argument, and we had no choice but to do\r\n```python\r\ninst_arg = ctx.args[0][0]\r\n\r\nassert isinstance(ctx.api, TypeChecker)\r\ninst_type = ctx.api.expr_checker.accept(inst_arg)\r\n```\r\n\r\nActual argument types are passed to the **function hook**, but then it's too late since arguments were already checked, and the hook can only affect the callee's return type.\r\n\r\nI'm not sure what's the best approach:\r\n\r\n1. Add equivalent of `CheckerPluginInterface.accept` for ad-hoc type resolution (i.e. current solution but w/o private API). The assumption is that this will not normally be used by hook authors except in specific cases for specific args (since doing it generally creates a chicken-and-egg problem, as `infer_arg_types_in_context` gets the callee after the hook's mutation).\r\n2. Pass actual arg types to **function sig hook**. Not sure it'll be doable, since as I mentioned `infer_arg_types_in_context` depends on `callee` (after hook's mutation).\r\n3. Change **function hook** to allow returning not only a ret_type but also arg_types/kinds/names. This means that in those cases checks will be done twice: it first has to pass old formal sig, then (if plugin returns one) it has to pass the new formal sig.\r\n\r\nPlease advise :)\r\n\r\nP.S. Same applies to method signature hook.","author":{"url":"https://github.com/ikonst","@type":"Person","name":"ikonst"},"datePublished":"2023-03-06T16:28:53Z","url":"https://github.com/python/mypy/issues/14845"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7d7c77a7-138b-c6d9-87d5-cba6dba710c8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E7EE:24D752:4525F9:5D5C5A:6B002C88 |
| html-safe-nonce | 199873aca1edfed3f77de83602d7f5d5b634290be5a99eb57048b93c40752571 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFN0VFOjI0RDc1Mjo0NTI1Rjk6NUQ1QzVBOjZCMDAyQzg4IiwidmlzaXRvcl9pZCI6IjY2NjcyMDY0ODk5MDU1NzMwMDAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 8a253d4ea8afdfd7abc30b876b57ae4512bb2afb579a57acbb74bf7663928371 |
| hovercard-subject-tag | issue:1611798664 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/python/mypy/14845/issue_layout |
| twitter:image | https://opengraph.githubassets.com/00032060ba889b231eacff6e2a63f8bd4917507ba87e667679f5de1a8ad83fb3/python/mypy/issues/14845 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/00032060ba889b231eacff6e2a63f8bd4917507ba87e667679f5de1a8ad83fb3/python/mypy/issues/14845 |
| og:image:alt | When executing (plugin) function signature hooks, actual argument types are not available yet (and, in fact, there's no caller context). In #14526, the signature of attr.evolve(inst, ...) depended ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ikonst |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width