Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type signature of @property not shown in help() #83306

Open
McSinyx mannequin opened this issue Dec 23, 2019 · 5 comments
Open

Type signature of @property not shown in help() #83306

McSinyx mannequin opened this issue Dec 23, 2019 · 5 comments
Labels
3.9 only security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement

Comments

@McSinyx
Copy link
Mannequin

McSinyx mannequin commented Dec 23, 2019

BPO 39125
Nosy @rhettinger, @McSinyx, @tirkarthi

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2019-12-23.15:40:00.651>
labels = ['type-feature', '3.9', 'docs']
title = 'Type signature of @property not shown in help()'
updated_at = <Date 2021-04-11.00:19:47.157>
user = 'https://github.com/McSinyx'

bugs.python.org fields:

activity = <Date 2021-04-11.00:19:47.157>
actor = 'rhettinger'
assignee = 'docs@python'
closed = False
closed_date = None
closer = None
components = ['Documentation']
creation = <Date 2019-12-23.15:40:00.651>
creator = 'McSinyx'
dependencies = []
files = []
hgrepos = []
issue_num = 39125
keywords = []
message_count = 5.0
messages = ['358823', '358825', '359041', '390625', '390754']
nosy_count = 5.0
nosy_names = ['rhettinger', 'docs@python', 'McSinyx', 'xtreak', 'brenthuisman']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue39125'
versions = ['Python 3.9']

@McSinyx
Copy link
Mannequin Author

McSinyx mannequin commented Dec 23, 2019

Dear Maintainer,

I want to request a feature on the generative documentation of type-hinting.
As of December 2019, I believe there is no support for generating such
information in help(). For demonstration, I have this tiny piece of code

class Foo:
    @property
    def bar(self) -> int: return 42

    @bar.setter
    def bar(self, value: int) -> None: pass

    def baz(self, arg: float) -> str: pass

whose documentation on CPython 3.7.5 (on Debian testing amd64 if that matters)
is generated as

class Foo(builtins.object)
 |  Methods defined here:
 |  
 |  baz(self, arg: float) -> str
 |  
 |  

| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| bar

I expect the documentation for bar to be as informative as bar, i.e. something
similar to ``bar: int''. As pointed out by ChrisWarrick on freenode#python,
the annotations are already present, yet help() is not making use of them:

>>> Foo.bar.fget.__annotations__
{'return': <class 'int'>}
>>> Foo.bar.fset.__annotations__
{'value': <class 'int'>, 'return': None}

Have a Merry Christmas or other holiday of your choice,
Nguyễn Gia Phong

@McSinyx McSinyx mannequin added 3.7 (EOL) end of life 3.8 (EOL) end of life 3.9 only security fixes labels Dec 23, 2019
@McSinyx McSinyx mannequin assigned docspython Dec 23, 2019
@McSinyx McSinyx mannequin added docs Documentation in the Doc dir type-feature A feature request or enhancement 3.7 (EOL) end of life 3.8 (EOL) end of life 3.9 only security fixes labels Dec 23, 2019
@McSinyx McSinyx mannequin assigned docspython Dec 23, 2019
@McSinyx McSinyx mannequin added docs Documentation in the Doc dir type-feature A feature request or enhancement labels Dec 23, 2019
@tirkarthi
Copy link
Member

Currently docstring written for even property.setter is ignored in help as inspect.getdoc only inspects property.fget [0] for docstrings. I feel docs for setter could also be included. The docs also indicate the same at https://docs.python.org/3.6/library/functions.html#property . In the absence of docs maybe the signature for getter and setter could be included as per this proposal.

class Foo:
    @property
    def bar(self) -> int:
        '''Bar docs for property'''
        return 42

    @bar.setter
    def bar(self, value: int) -> None:
        '''Bar docs for setter'''
        pass

help(Foo.bar)

Help on property:

Bar docs for property

[0]

elif isinstance(obj, property):

@tirkarthi tirkarthi removed 3.7 (EOL) end of life 3.8 (EOL) end of life labels Dec 23, 2019
@McSinyx
Copy link
Mannequin Author

McSinyx mannequin commented Dec 30, 2019

Relating to this, should there also be indication about the mode (get, set, del) the property? Currently there is no way to tell if the *attribute* is read-only, read-write or write-only.

@McSinyx McSinyx mannequin added 3.9 only security fixes and removed 3.9 only security fixes labels Dec 30, 2019
@brenthuisman
Copy link
Mannequin

brenthuisman mannequin commented Apr 9, 2021

Is there any activity on this issue? The way Pybind11 generates accessors for attributes makes (as properties with getter and setter) makes it currently impossible to view the type info, which Pybind does provide.

Thanks for any update.

@rhettinger
Copy link
Contributor

Currently there is no way to tell if the *attribute*
is read-only, read-write or write-only.

Read-only is segregated in the help() output.

>>> class A:
        @property
        def computed_field(self):
            'An example property'

        
>>> help(A)
Help on class A in module __main__:
class A(builtins.object)
 |  Readonly properties defined here:
 |  
 |  computed_field
 |      An example property
 |  
 |  

| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.9 only security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants