This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Copy property return annotations to __annotations__
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.9, Python 3.8, Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Eric Wieser, Eric.Wieser, levkivskyi
Priority: normal Keywords: patch

Created on 2020-05-12 09:11 by Eric Wieser, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 20052 open Eric.Wieser, 2020-05-12 09:12
Messages (1)
msg368710 - (view) Author: Eric Wieser (Eric Wieser) Date: 2020-05-12 09:11
Consider a class like

    class MyClass:
        x: int
        y: int

Which has

    >>> MyClass.__annotations__
    {'x': int, 'y': int}

In future, it might change to

    class MyClass:
        @property
        def x(self) -> int:
            ...
        @functools.cached_property
        def x(self) -> int:
            ...

Most code won't be able to tell the difference, as properties are already a mostly-transparent replacement for attributes - but any code looking at `__annotations__` will find it is now absent.

It would be handy if `property.__set_name__` and `cachedproperty.__set_name__` could populate the `__annotations__` dict from their return type annotation.

This isn't just hypothetically useful - `sphinx` master as of https://github.com/sphinx-doc/sphinx/pull/7564 is able to retrieve the type of any descriptor with this behavior.
History
Date User Action Args
2022-04-11 14:59:30adminsetgithub: 84786
2020-05-15 21:04:13levkivskyisetnosy: + levkivskyi
2020-05-12 09:12:49Eric.Wiesersetkeywords: + patch
nosy: + Eric.Wieser

pull_requests: + pull_request19361
stage: patch review
2020-05-12 09:11:47Eric Wiesercreate