Title: AbstractContextManager.__enter__ not properly annotated · Issue #13950 · python/typeshed · GitHub
Open Graph Title: AbstractContextManager.__enter__ not properly annotated · Issue #13950 · python/typeshed
X Title: AbstractContextManager.__enter__ not properly annotated · Issue #13950 · python/typeshed
Description: Per the Python docs, AbstractContextManager provides a default __enter__ implementation which just returns self. But this does not appear to be properly type annotated (using Self): from typing import reveal_type, Optional, Self from typ...
Open Graph Description: Per the Python docs, AbstractContextManager provides a default __enter__ implementation which just returns self. But this does not appear to be properly type annotated (using Self): from typing imp...
X Description: Per the Python docs, AbstractContextManager provides a default __enter__ implementation which just returns self. But this does not appear to be properly type annotated (using Self): from typing imp...
Opengraph URL: https://github.com/python/typeshed/issues/13950
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"AbstractContextManager.__enter__ not properly annotated","articleBody":"Per the Python docs, `AbstractContextManager` provides a default `__enter__` implementation which just returns `self`. But this does not appear to be properly type annotated (using `Self`):\n\n```python\nfrom typing import reveal_type, Optional, Self\nfrom types import TracebackType\nfrom contextlib import AbstractContextManager\n\nclass A1(AbstractContextManager):\n def __exit__( # pylint: disable=useless-return\n self, exc_type: Optional[type[BaseException]],\n exc_val: Optional[BaseException],\n exc_tb: Optional[TracebackType]) -> Optional[bool]:\n return None\n\nclass A2(AbstractContextManager):\n def __exit__( # pylint: disable=useless-return\n self, exc_type: Optional[type[BaseException]],\n exc_val: Optional[BaseException],\n exc_tb: Optional[TracebackType]) -> Optional[bool]:\n return None\n\n def __enter__(self) -> Self:\n return self\n\nclass B1(A1):\n pass\n\nclass B2(A2):\n pass\n\nwith B1() as d1:\n reveal_type(d1)\n\nwith B2() as d2:\n reveal_type(d2)\n```\n\n[Running this with `mypy`](https://mypy-play.net/?mypy=latest&python=3.13&gist=e9e6697dc12768b01b56f785f0827b72), only the second case properly reveals the type as `B2`. The first one just says `Any`.\n\nAt runtime, the behavior of both is identical.\n\nI have recreated this on both Python 3.12 and Python 3.13.","author":{"url":"https://github.com/mharding-hpe","@type":"Person","name":"mharding-hpe"},"datePublished":"2025-05-05T21:14:43Z","url":"https://github.com/python/typeshed/issues/13950"}
| 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:0a102af9-b1fc-d26e-35a0-703d8b96761d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8B60:374654:8B0E5:B494F:6AFF8D7B |
| html-safe-nonce | 466d23eb7d6ffe85b6fee751deacc1632efca5cbb93f6d32433ebdf8bdab8630 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QjYwOjM3NDY1NDo4QjBFNTpCNDk0Rjo2QUZGOEQ3QiIsInZpc2l0b3JfaWQiOiI4Njg2MzkzNzY1MzUyNDEwNDkxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 97784c6d90ecb3682c5bc62516b2cb9e5a7a44841fabfdd316ff7eeb6b755e62 |
| hovercard-subject-tag | issue:3041696049 |
| 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/13950/issue_layout |
| twitter:image | https://opengraph.githubassets.com/840c087f476b533578dfb911acc5ba09fc3bec5f19e6e7b80b50b475ef1c8ee2/python/typeshed/issues/13950 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/840c087f476b533578dfb911acc5ba09fc3bec5f19e6e7b80b50b475ef1c8ee2/python/typeshed/issues/13950 |
| og:image:alt | Per the Python docs, AbstractContextManager provides a default __enter__ implementation which just returns self. But this does not appear to be properly type annotated (using Self): from typing imp... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mharding-hpe |
| hostname | github.com |
| expected-hostname | github.com |
| None | 587ad99a3e443b2e1cb0d3df059ec49ab54389861f13310766dfdeb615fed90d |
| 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 | 5bb0fb68d64881d1344f5863d809515d496801e5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width