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

Builtin __bool__ docstrings are wrong #90888

Closed
JelleZijlstra opened this issue Feb 12, 2022 · 5 comments
Closed

Builtin __bool__ docstrings are wrong #90888

JelleZijlstra opened this issue Feb 12, 2022 · 5 comments
Assignees
Labels
3.11 bug and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@JelleZijlstra
Copy link
Member

BPO 46732
Nosy @terryjreedy, @JelleZijlstra, @miss-islington
PRs
  • bpo-46732: fix __bool__ docstring #31301
  • [3.10] bpo-46732: fix __bool__ docstring (GH-31301) #31473
  • [3.9] bpo-46732: fix __bool__ docstring (GH-31301) #31474
  • 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 = 'https://github.com/JelleZijlstra'
    closed_at = <Date 2022-02-21.17:19:35.177>
    created_at = <Date 2022-02-12.19:10:01.907>
    labels = ['interpreter-core', 'type-bug', '3.11']
    title = 'Builtin __bool__ docstrings are wrong'
    updated_at = <Date 2022-02-21.17:19:35.177>
    user = 'https://github.com/JelleZijlstra'

    bugs.python.org fields:

    activity = <Date 2022-02-21.17:19:35.177>
    actor = 'JelleZijlstra'
    assignee = 'JelleZijlstra'
    closed = True
    closed_date = <Date 2022-02-21.17:19:35.177>
    closer = 'JelleZijlstra'
    components = ['Interpreter Core']
    creation = <Date 2022-02-12.19:10:01.907>
    creator = 'JelleZijlstra'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46732
    keywords = ['patch']
    message_count = 5.0
    messages = ['413141', '413505', '413628', '413660', '413661']
    nosy_count = 3.0
    nosy_names = ['terry.reedy', 'JelleZijlstra', 'miss-islington']
    pr_nums = ['31301', '31473', '31474']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue46732'
    versions = ['Python 3.11']

    @JelleZijlstra
    Copy link
    Member Author

    >>> None.__bool__.__doc__
    'self != 0'

    This isn't true, since None does not equal 0. I suggest rewording it to "True if self else False".

    @JelleZijlstra JelleZijlstra added the 3.11 bug and security fixes label Feb 12, 2022
    @JelleZijlstra JelleZijlstra self-assigned this Feb 12, 2022
    @JelleZijlstra JelleZijlstra added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error 3.11 bug and security fixes labels Feb 12, 2022
    @JelleZijlstra JelleZijlstra self-assigned this Feb 12, 2022
    @JelleZijlstra JelleZijlstra added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Feb 12, 2022
    @terryjreedy
    Copy link
    Member

    There is no object.__bool__. None.__bool__.__doc__ appears to be an accidental copy of bool/int/float/complex.__bool__.__doc__. It should just be 'False'.

    @terryjreedy terryjreedy changed the title object.__bool__ docstring is wrong None.__bool__ docstring is wrong Feb 18, 2022
    @terryjreedy terryjreedy changed the title object.__bool__ docstring is wrong None.__bool__ docstring is wrong Feb 18, 2022
    @terryjreedy
    Copy link
    Member

    For whatever reason, all builtins with a __bool__ method appear to share the same docstring. For example,

    >>> range.__bool__.__doc__
    'self != 0'
    >>> bool(range(0))
    False
    >>> bool(range(1))
    True

    The concrete collection classes have their lengths stored internally so bool use that via len(self). But len(range) != 0 iff stop != start.

    @terryjreedy terryjreedy changed the title None.__bool__ docstring is wrong Builtin __bool__ docstrings are wrong Feb 21, 2022
    @terryjreedy terryjreedy changed the title None.__bool__ docstring is wrong Builtin __bool__ docstrings are wrong Feb 21, 2022
    @miss-islington
    Copy link
    Contributor

    New changeset c596ecb by Miss Islington (bot) in branch '3.10':
    [3.10] bpo-46732: fix __bool__ docstring (GH-31301) (GH-31473)
    c596ecb

    @miss-islington
    Copy link
    Contributor

    New changeset 8eb18d8 by Miss Islington (bot) in branch '3.9':
    [3.9] bpo-46732: fix __bool__ docstring (GH-31301) (GH-31474)
    8eb18d8

    @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.11 bug and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants