René's URL Explorer Experiment


Title: Make `builtins.property` generic · Issue #985 · python/typing · GitHub

Open Graph Title: Make `builtins.property` generic · Issue #985 · python/typing

X Title: Make `builtins.property` generic · Issue #985 · python/typing

Description: Hi! Here's how property type is defined right now from a typing perspective: from typing import Any, Callable class property(object): fget: Callable[[Any], Any] | None fset: Callable[[Any, Any], None] | None fdel: Callable[[Any], None] |...

Open Graph Description: Hi! Here's how property type is defined right now from a typing perspective: from typing import Any, Callable class property(object): fget: Callable[[Any], Any] | None fset: Callable[[Any, Any], No...

X Description: Hi! Here's how property type is defined right now from a typing perspective: from typing import Any, Callable class property(object): fget: Callable[[Any], Any] | None fset: Callable[[Any, Any]...

Opengraph URL: https://github.com/python/typing/issues/985

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Make `builtins.property` generic","articleBody":"Hi!\r\n\r\nHere's how `property` type is defined right now from a typing perspective: \r\n\r\n```python\r\nfrom typing import Any, Callable\r\n\r\nclass property(object):\r\n    fget: Callable[[Any], Any] | None\r\n    fset: Callable[[Any, Any], None] | None\r\n    fdel: Callable[[Any], None] | None\r\n    def __init__(\r\n        self,\r\n        fget: Callable[[Any], Any] | None = ...,\r\n        fset: Callable[[Any, Any], None] | None = ...,\r\n        fdel: Callable[[Any], None] | None = ...,\r\n        doc: str | None = ...,\r\n    ) -> None: ...\r\n    def getter(self, __fget: Callable[[Any], Any]) -> property: ...\r\n    def setter(self, __fset: Callable[[Any, Any], None]) -> property: ...\r\n    def deleter(self, __fdel: Callable[[Any], None]) -> property: ...\r\n    def __get__(self, __obj: Any, __type: type | None = ...) -> Any: ...\r\n    def __set__(self, __obj: Any, __value: Any) -> None: ...\r\n    def __delete__(self, __obj: Any) -> None: ...\r\n```\r\n\r\nSource: https://github.com/python/typeshed/blob/12b79f64d7241024447eae8ca5d52779cca94ee7/stdlib/builtins.pyi#L947\r\n\r\nNote, that it is not generic. But, this is a type that surely can be modeled as a generic type.\r\n\r\n## Motivation\r\n\r\nWhy? Because `@property` works with two major scenarios: getting some inner type and setting some extrenal type. This can be represented as `property[GetType, SetType]`. \r\n\r\nIt might not seem very important to end users, because of how `@property`s are used, but it quite importatnt for type-checkers and type stubs.\r\n\r\nHere are some problems that we have in `mypy` with properties:\r\n- Because `@property` is so special right now, `mypy` does not support decorated properties: https://github.com/python/mypy/issues/1362\r\n- Mypy does not support `@property` with different `@setter` type: https://github.com/python/mypy/issues/3004 and https://github.com/python/mypy/pull/11643\r\n\r\nYes, we can work around the fact we cannot simply express `property[GetType, SetType]`, but I don't think that missing this important detail is good for the typing system in the long run.\r\nWithout this change we cannot treat `@property` as a regular descriptor, which follows the same rules.\r\n\r\n## Reference implementation\r\n\r\nImplementing generic `@property` will require several changes.\r\n\r\n### CPython\r\n\r\nI guess we would need something similar as we did in https://www.python.org/dev/peps/pep-0585/\r\n\r\nSomething like adding:\r\n\r\n```c\r\n{\"__class_getitem__\", Py_GenericAlias, METH_O\\|METH_CLASS, PyDoc_STR(\"See PEP 585\")},\r\n```\r\n\r\nHere: https://github.com/python/cpython/blob/c8749b578324ad4089c8d014d9136bc42b065343/Objects/descrobject.c#L1567-L1568\r\n\r\n### typeshed\r\n\r\nI am sure that this code can be improved, but it does its job as a reference / demo:\r\n\r\n```python\r\nfrom typing import Any, Callable, Generic\r\n\r\nG = TypeVar('G')  # think about variance\r\nS = TypeVar('S')\r\n\r\nclass property(Generic[G, S]):\r\n    fget: Callable[[Any], G] | None\r\n    fset: Callable[[Any, S], None] | None\r\n    fdel: Callable[[Any], None] | None\r\n    def __init__(\r\n        self,\r\n        fget: Callable[[Any], G] | None = ...,\r\n        fset: Callable[[Any, S], None] | None = ...,\r\n        fdel: Callable[[Any], None] | None = ...,\r\n        doc: str | None = ...,\r\n    ) -> None: ...\r\n    def getter(self, __fget: Callable[[Any], G]) -> property: ...\r\n    def setter(self, __fset: Callable[[Any, S], None]) -> property: ...\r\n    def deleter(self, __fdel: Callable[[Any], None]) -> property: ...\r\n    def __get__(self, __obj: Any, __type: type | None = ...) -> Any: ...\r\n    def __set__(self, __obj: Any, __value: Any) -> None: ...\r\n    def __delete__(self, __obj: Any) -> None: ...\r\n```\r\n\r\nPlayground: https://mypy-play.net/?mypy=latest&python=3.10&flags=strict%2Cdisallow-subclassing-any%2Cdisallow-untyped-calls%2Cdisallow-untyped-decorators&gist=e7cec4565d416a0981d4a65e619f1be6\r\n\r\nIt almost works as-is, but `@property.setter` part requires some extra handling from type-checkers.\r\n\r\n## Backwards compatibility\r\n\r\nAs far as I understand CPython's development process, we can add this new feature to 3.11 only.\r\nI think that using `from __future__ import annotations` should also work for `@property` the same way [PEP585](https://www.python.org/dev/peps/pep-0585/#implementation) defines.\r\n\r\n## Next steps\r\n\r\nIf others agree with me that `property[GetType, SetType]` is a good thing to have, I can:\r\n- [x] Open new BPO issue for this feature: https://bugs.python.org/issue46162\r\n- [x] Add runtime support for `property.__class_getitem__` to CPython: https://github.com/python/cpython/pull/30238\r\n- [ ] Send a PR to `typeshed` with the typing stub\r\n- [ ] Maybe update PEP585?\r\n\r\nLooking forward to your feedback! 😊 \r\n\r\n## Related issues\r\n\r\nRefs:\r\n- https://github.com/python/typing/issues/594 (I think that adding `typing.Property` does not really make much sense, since `python>=3.9` already supports other builtin generic types).\r\n- https://github.com/python/typing/issues/758","author":{"url":"https://github.com/sobolevn","@type":"Person","name":"sobolevn"},"datePublished":"2021-12-19T18:20:52Z","url":"https://github.com/python/typing/issues/985"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:0e2c0297-e946-b582-2570-6d5f90200e22
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD844:2F2EB9:2D9CC2D:3C6484A:6B0023C0
html-safe-nonce5dc7688941a8cd74d9a69fcf855db87402eb50a11e01a43b03406848039ac740
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEODQ0OjJGMkVCOToyRDlDQzJEOjNDNjQ4NEE6NkIwMDIzQzAiLCJ2aXNpdG9yX2lkIjoiNDc0ODUxMzU3NjUxMDAzODk3NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacd1a2a8eb734884977c86980ab0805f5c172d682def314cde4899dc31e0fd8145
hovercard-subject-tagissue:1084160579
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/typing/985/issue_layout
twitter:imagehttps://opengraph.githubassets.com/1214b37a4fccc8b0a8b37d501b0e918455a74e1bc76849c5511c4a8ded690af7/python/typing/issues/985
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/1214b37a4fccc8b0a8b37d501b0e918455a74e1bc76849c5511c4a8ded690af7/python/typing/issues/985
og:image:altHi! Here's how property type is defined right now from a typing perspective: from typing import Any, Callable class property(object): fget: Callable[[Any], Any] | None fset: Callable[[Any, Any], No...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamesobolevn
hostnamegithub.com
expected-hostnamegithub.com
None4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0
turbo-cache-controlno-preview
go-importgithub.com/python/typing git https://github.com/python/typing.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id24604008
octolytics-dimension-repository_nwopython/typing
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id24604008
octolytics-dimension-repository_network_root_nwopython/typing
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release44c658b24abf00491fb7ae5f56d42c9f38cbeab2
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/typing/issues/985#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Ftyping%2Fissues%2F985
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Ftyping%2Fissues%2F985
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Ftyping
Reloadhttps://github.com/python/typing/issues/985
Reloadhttps://github.com/python/typing/issues/985
Reloadhttps://github.com/python/typing/issues/985
pythonhttps://github.com/python
typinghttps://github.com/python/typing
Codehttps://github.com/python/typing
Issues206 (206)https://github.com/python/typing/issues
Pull requests27 (27)https://github.com/python/typing/pulls
Discussionshttps://github.com/python/typing/discussions
Actionshttps://github.com/python/typing/actions
Security and qualityhttps://github.com/python/typing/security
Insightshttps://github.com/python/typing/insights
https://github.com/python/typing
New issuehttps://github.com/login?return_to=https://github.com/python/typing/issues/985
New issuehttps://github.com/login?return_to=https://github.com/python/typing/issues/985
Make builtins.property generichttps://github.com/python/typing/issues/985#top
topic: featureDiscussions about new features for Python's type annotationshttps://github.com/python/typing/issues?q=state%3Aopen%20label%3A%22topic%3A%20feature%22
https://github.com/sobolevn
sobolevnhttps://github.com/sobolevn
on Dec 19, 2021https://github.com/python/typing/issues/985#issue-1084160579
https://github.com/python/typeshed/blob/12b79f64d7241024447eae8ca5d52779cca94ee7/stdlib/builtins.pyi#L947https://github.com/python/typeshed/blob/12b79f64d7241024447eae8ca5d52779cca94ee7/stdlib/builtins.pyi#L947
Decorated property not supported mypy#1362https://github.com/python/mypy/issues/1362
What to do about setters of a different type than their property? mypy#3004https://github.com/python/mypy/issues/3004
Recognize different setter type for properties. mypy#11643https://github.com/python/mypy/pull/11643
https://www.python.org/dev/peps/pep-0585/https://www.python.org/dev/peps/pep-0585/
https://github.com/python/cpython/blob/c8749b578324ad4089c8d014d9136bc42b065343/Objects/descrobject.c#L1567-L1568https://github.com/python/cpython/blob/c8749b578324ad4089c8d014d9136bc42b065343/Objects/descrobject.c#L1567-L1568
https://mypy-play.net/?mypy=latest&python=3.10&flags=strict%2Cdisallow-subclassing-any%2Cdisallow-untyped-calls%2Cdisallow-untyped-decorators&gist=e7cec4565d416a0981d4a65e619f1be6https://mypy-play.net/?mypy=latest&python=3.10&flags=strict%2Cdisallow-subclassing-any%2Cdisallow-untyped-calls%2Cdisallow-untyped-decorators&gist=e7cec4565d416a0981d4a65e619f1be6
PEP585https://www.python.org/dev/peps/pep-0585/#implementation
https://bugs.python.org/issue46162https://bugs.python.org/issue46162
bpo-46162: make property generic cpython#30238https://github.com/python/cpython/pull/30238
Add typing.Property #594https://github.com/python/typing/issues/594
Feature Request: Add a generic property class #758https://github.com/python/typing/issues/758
sobolevnhttps://github.com/sobolevn
topic: featureDiscussions about new features for Python's type annotationshttps://github.com/python/typing/issues?q=state%3Aopen%20label%3A%22topic%3A%20feature%22
on Dec 19, 2021https://github.com/python/typing/issues/985#event-5789407088
https://github.com/AlexWaygood
AlexWaygoodhttps://github.com/AlexWaygood
on Dec 19, 2021https://github.com/python/typing/issues/985#issuecomment-997439829
"class property" should be Generic[T] typeshed#4731https://github.com/python/typeshed/issues/4731
make property generic typeshed#5987https://github.com/python/typeshed/pull/5987
https://github.com/hauntsaninja
hauntsaninjahttps://github.com/hauntsaninja
on Dec 19, 2021https://github.com/python/typing/issues/985#issuecomment-997450422
https://github.com/sobolevn
sobolevnhttps://github.com/sobolevn
on Dec 19, 2021https://github.com/python/typing/issues/985#issuecomment-997457963
@erictrauthttps://github.com/erictraut
python/typeshed#5987https://github.com/python/typeshed/pull/5987
python/mypy#11719 (comment)https://github.com/python/mypy/pull/11719#issuecomment-992278610
https://github.com/ariebovenberg
ariebovenberghttps://github.com/ariebovenberg
on Dec 20, 2021https://github.com/python/typing/issues/985#issuecomment-997650789
#922 (comment)https://github.com/python/typing/issues/922#issuecomment-985851682
https://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
on Dec 20, 2021https://github.com/python/typing/issues/985#issuecomment-998195004
https://github.com/JelleZijlstra
JelleZijlstrahttps://github.com/JelleZijlstra
on Dec 20, 2021https://github.com/python/typing/issues/985#issuecomment-998204899
https://github.com/sobolevn
sobolevnhttps://github.com/sobolevn
on Dec 20, 2021https://github.com/python/typing/issues/985#issuecomment-998205172
https://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
on Dec 20, 2021https://github.com/python/typing/issues/985#issuecomment-998221181
https://github.com/sobolevn
sobolevnhttps://github.com/sobolevn
on Dec 26, 2021https://github.com/python/typing/issues/985#issuecomment-1001126888
@erictrauthttps://github.com/erictraut
@rchen152https://github.com/rchen152
https://github.com/erictraut
erictrauthttps://github.com/erictraut
on Dec 29, 2021https://github.com/python/typing/issues/985#issuecomment-1002770338
https://github.com/sobolevn
sobolevnhttps://github.com/sobolevn
on Jan 11, 2022https://github.com/python/typing/issues/985#issuecomment-1009709691
sobolevnhttps://github.com/sobolevn
completedhttps://github.com/python/typing/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Jan 11, 2022https://github.com/python/typing/issues/985#event-5871253148
https://github.com/ofek
ofekhttps://github.com/ofek
on Dec 17, 2022https://github.com/python/typing/issues/985#issuecomment-1356416733
@sobolevnhttps://github.com/sobolevn
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/typing/issues/985
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/typing/issues/985
topic: featureDiscussions about new features for Python's type annotationshttps://github.com/python/typing/issues?q=state%3Aopen%20label%3A%22topic%3A%20feature%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.