Title: How to use _typeshed.wsgi with typing.get_type_hints · Issue #11004 · python/typeshed · GitHub
Open Graph Title: How to use _typeshed.wsgi with typing.get_type_hints · Issue #11004 · python/typeshed
X Title: How to use _typeshed.wsgi with typing.get_type_hints · Issue #11004 · python/typeshed
Description: Hello there, is there a way to get to work combination of _typeshed.wsgi and typing.get_type_hints in runtime? In flask codebase there is something like from __future__ import annotations import typing as t if t.TYPE_CHECKING: # pragma: ...
Open Graph Description: Hello there, is there a way to get to work combination of _typeshed.wsgi and typing.get_type_hints in runtime? In flask codebase there is something like from __future__ import annotations import ty...
X Description: Hello there, is there a way to get to work combination of _typeshed.wsgi and typing.get_type_hints in runtime? In flask codebase there is something like from __future__ import annotations import ty...
Opengraph URL: https://github.com/python/typeshed/issues/11004
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"How to use _typeshed.wsgi with typing.get_type_hints","articleBody":"Hello there,\r\nis there a way to get to work combination of `_typeshed.wsgi` and `typing.get_type_hints` in runtime?\r\nIn flask codebase there is something like\r\n```py\r\nfrom __future__ import annotations\r\n\r\nimport typing as t\r\n\r\nif t.TYPE_CHECKING: # pragma: no cover\r\n from _typeshed.wsgi import WSGIApplication # noqa: F401\r\n from werkzeug.datastructures import Headers # noqa: F401\r\n from werkzeug.sansio.response import Response # noqa: F401\r\n\r\n# The possible types that are directly convertible or are a Response object.\r\nResponseValue = t.Union[\r\n \"Response\",\r\n str,\r\n bytes,\r\n t.List[t.Any],\r\n # Only dict is actually accepted, but Mapping allows for TypedDict.\r\n t.Mapping[str, t.Any],\r\n t.Iterator[str],\r\n t.Iterator[bytes],\r\n]\r\n\r\n# the possible types for an individual HTTP header\r\n# This should be a Union, but mypy doesn't pass unless it's a TypeVar.\r\nHeaderValue = t.Union[str, t.List[str], t.Tuple[str, ...]]\r\n\r\n# the possible types for HTTP headers\r\nHeadersValue = t.Union[\r\n \"Headers\",\r\n t.Mapping[str, HeaderValue],\r\n t.Sequence[t.Tuple[str, HeaderValue]],\r\n]\r\n\r\n# The possible types returned by a route function.\r\nResponseReturnValue = t.Union[\r\n ResponseValue,\r\n t.Tuple[ResponseValue, HeadersValue],\r\n t.Tuple[ResponseValue, int],\r\n t.Tuple[ResponseValue, int, HeadersValue],\r\n \"WSGIApplication\",\r\n]\r\n```\r\nhttps://github.com/pallets/flask/blob/3.0.0/src/flask/typing.py\r\nand in my application I use something like\r\n```py\r\nfrom flask.typing import ResponseReturnValue\r\n\r\n@inject\r\ndef my_endpoint() -> ResponseReturnValue:\r\n return \"asdf\"\r\n\r\n...\r\ndef inject(method):\r\n ...\r\n arg_types = typing.get_type_hints(method)\r\n # get args from DI container and call actual function with injected args\r\n```\r\nwhich ends with error like\r\n```\r\nNameError: name 'Response' is not defined\r\n```\r\nHere is complete playground for my issue https://www.online-python.com/AsZX867MEO\r\n\r\nI can probably use my own type for that - that's why I ask here - but not sure how to use typeshed in runtime.\r\nThen I can probably send PR directly to flask with fix for such edge cases (as nobody probably encountered this based on how long this is in flask already).\r\n\r\nThanks for you tips and help in advice.","author":{"url":"https://github.com/adaamz","@type":"Person","name":"adaamz"},"datePublished":"2023-11-09T23:09:10Z","url":"https://github.com/python/typeshed/issues/11004"}
| 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:e49262cf-87a1-ede8-46eb-e417d09dddcd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9758:1D6507:5256C9:6A4D2B:6AFFC230 |
| html-safe-nonce | fcd0acbaaef08e55ad6fc9f427a4d1cef3a5b270215efdec59240d8fa1cbb260 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NzU4OjFENjUwNzo1MjU2Qzk6NkE0RDJCOjZBRkZDMjMwIiwidmlzaXRvcl9pZCI6IjEwMzY0NjQ2NzA3NjE3OTYxNDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c813431a9d8e0686dc50ed006a0162b38dfbdc9cfe536ab06a688cfd7268d018 |
| hovercard-subject-tag | issue:1986557350 |
| 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/typeshed/11004/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ebe8422c35ae8c1d7ed60e77634ed941788ad22923e1842ddfd8a01d627546e6/python/typeshed/issues/11004 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ebe8422c35ae8c1d7ed60e77634ed941788ad22923e1842ddfd8a01d627546e6/python/typeshed/issues/11004 |
| og:image:alt | Hello there, is there a way to get to work combination of _typeshed.wsgi and typing.get_type_hints in runtime? In flask codebase there is something like from __future__ import annotations import ty... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | adaamz |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1e805b832df235bb21305db712c3b6432920019dfc12cb25b9cb8d3b0c9403cf |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typeshed git https://github.com/python/typeshed.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 31696383 |
| octolytics-dimension-repository_nwo | python/typeshed |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 31696383 |
| octolytics-dimension-repository_network_root_nwo | python/typeshed |
| 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 | 8fa4a54e6871c7908eda1c246ad5972982c0b59d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width