Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

help() on types has strange (if defined) notice for attributes that are defined #112266

Copy link
Copy link
Closed
@sobolevn

Description

@sobolevn
Issue body actions

Feature or enhancement

Let's say we have a regular class and we call help() on it:

>>> class A: ...
... 
>>> help(A)
Help on class A in module __main__:

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

This leaves a strange impression: what does it mean for __dict__?

dictionary for instance variables (if defined)

It is defined.

The same for regular __doc__:

>>> A.__dict__['__dict__'].__doc__
'dictionary for instance variables (if defined)'

Let's see what happens when __dict__ and __weakref__ are not defined:

>>> class B:
...    __slots__ = ()
... 
>>> help(B)
Help on class B in module __main__:

class B(builtins.object)

And:

>>> B.__dict__['__dict__']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    B.__dict__['__dict__']
    ~~~~~~~~~~^^^^^^^^^^^^
KeyError: '__dict__'

The historical reason behind it is: 373c741#diff-1decebeef15f4e0b0ce106c665751ec55068d4d1d1825847925ad4f528b5b872R1356-R1377

What do others think: should we remove (if defined) part?
If so, I have a PR ready.

Linked PRs

Metadata

Metadata

Assignees

Labels

docsDocumentation in the Doc dirDocumentation in the Doc dirtype-featureA feature request or enhancementA feature request or enhancement

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.