Skip to content

operator library and inspect.signature clarity: "a" versus "obj"? #141334

@KardoPaska

Description

@KardoPaska

Documentation

Hello Friends!

For several operator methods, the inspect.signature is showing something different than the documentation. This is a minor issue.

For example:

  • operator.not_(obj) is documented as having obj argument in the html,
  • the mapping-operators-to-functions table shows a,
  • the inspect.signature shows a,

https://docs.python.org/3/library/operator.html#operator.not_
https://docs.python.org/3/library/operator.html#mapping-operators-to-functions

Why aren't all 3 the same?

Very few methods documented in html actually have obj as an argument, e.g., not, truth, abs, etc.

import operator
from inspect import signature

to_print_L = []
for attr in sorted(dir(operator)):
    try:
        f = getattr(operator, attr)
        sig = signature(f)
        to_print_L.append(' | '.join([f"{repr(f)   :<31}",
                                      f"{attr      :^13}",
                                      f"{repr(sig) :<21}",
                                      f"{tuple(sig.parameters)}"]))
    except (TypeError, ValueError):
        continue

for x in sorted(to_print_L):
    print(x)

Print output:

<built-in function abs>         |      abs      | <Signature (a, /)>    | ('a',)
<built-in function abs>         |     _abs      | <Signature (x, /)>    | ('x',)
<built-in function abs>         |    __abs__    | <Signature (a, /)>    | ('a',)
<built-in function add>         |      add      | <Signature (a, b, /)> | ('a', 'b')
<built-in function add>         |    __add__    | <Signature (a, b, /)> | ('a', 'b')
<built-in function and_>        |     and_      | <Signature (a, b, /)> | ('a', 'b')
<built-in function and_>        |    __and__    | <Signature (a, b, /)> | ('a', 'b')
<built-in function call>        |     call      | <Signature (obj, /, *args, **kwargs)> | ('obj', 'args', 'kwargs')
<built-in function call>        |   __call__    | <Signature (obj, /, *args, **kwargs)> | ('obj', 'args', 'kwargs')
<built-in function concat>      |    concat     | <Signature (a, b, /)> | ('a', 'b')
<built-in function concat>      |  __concat__   | <Signature (a, b, /)> | ('a', 'b')
<built-in function contains>    |   contains    | <Signature (a, b, /)> | ('a', 'b')
<built-in function contains>    | __contains__  | <Signature (a, b, /)> | ('a', 'b')
<built-in function countOf>     |    countOf    | <Signature (a, b, /)> | ('a', 'b')
<built-in function delitem>     |    delitem    | <Signature (a, b, /)> | ('a', 'b')
<built-in function delitem>     |  __delitem__  | <Signature (a, b, /)> | ('a', 'b')
<built-in function eq>          |      eq       | <Signature (a, b, /)> | ('a', 'b')
<built-in function eq>          |    __eq__     | <Signature (a, b, /)> | ('a', 'b')
<built-in function floordiv>    |   floordiv    | <Signature (a, b, /)> | ('a', 'b')
<built-in function floordiv>    | __floordiv__  | <Signature (a, b, /)> | ('a', 'b')
<built-in function ge>          |      ge       | <Signature (a, b, /)> | ('a', 'b')
<built-in function ge>          |    __ge__     | <Signature (a, b, /)> | ('a', 'b')
<built-in function getitem>     |    getitem    | <Signature (a, b, /)> | ('a', 'b')
<built-in function getitem>     |  __getitem__  | <Signature (a, b, /)> | ('a', 'b')
<built-in function gt>          |      gt       | <Signature (a, b, /)> | ('a', 'b')
<built-in function gt>          |    __gt__     | <Signature (a, b, /)> | ('a', 'b')
<built-in function iadd>        |     iadd      | <Signature (a, b, /)> | ('a', 'b')
<built-in function iadd>        |   __iadd__    | <Signature (a, b, /)> | ('a', 'b')
<built-in function iand>        |     iand      | <Signature (a, b, /)> | ('a', 'b')
<built-in function iand>        |   __iand__    | <Signature (a, b, /)> | ('a', 'b')
<built-in function iconcat>     |    iconcat    | <Signature (a, b, /)> | ('a', 'b')
<built-in function iconcat>     |  __iconcat__  | <Signature (a, b, /)> | ('a', 'b')
<built-in function ifloordiv>   |   ifloordiv   | <Signature (a, b, /)> | ('a', 'b')
<built-in function ifloordiv>   | __ifloordiv__ | <Signature (a, b, /)> | ('a', 'b')
<built-in function ilshift>     |    ilshift    | <Signature (a, b, /)> | ('a', 'b')
<built-in function ilshift>     |  __ilshift__  | <Signature (a, b, /)> | ('a', 'b')
<built-in function imatmul>     |    imatmul    | <Signature (a, b, /)> | ('a', 'b')
<built-in function imatmul>     |  __imatmul__  | <Signature (a, b, /)> | ('a', 'b')
<built-in function imod>        |     imod      | <Signature (a, b, /)> | ('a', 'b')
<built-in function imod>        |   __imod__    | <Signature (a, b, /)> | ('a', 'b')
<built-in function imul>        |     imul      | <Signature (a, b, /)> | ('a', 'b')
<built-in function imul>        |   __imul__    | <Signature (a, b, /)> | ('a', 'b')
<built-in function index>       |     index     | <Signature (a, /)>    | ('a',)
<built-in function index>       |   __index__   | <Signature (a, /)>    | ('a',)
<built-in function indexOf>     |    indexOf    | <Signature (a, b, /)> | ('a', 'b')
<built-in function inv>         |      inv      | <Signature (a, /)>    | ('a',)
<built-in function inv>         |    __inv__    | <Signature (a, /)>    | ('a',)
<built-in function invert>      |    invert     | <Signature (a, /)>    | ('a',)
<built-in function invert>      |  __invert__   | <Signature (a, /)>    | ('a',)
<built-in function ior>         |      ior      | <Signature (a, b, /)> | ('a', 'b')
<built-in function ior>         |    __ior__    | <Signature (a, b, /)> | ('a', 'b')
<built-in function ipow>        |     ipow      | <Signature (a, b, /)> | ('a', 'b')
<built-in function ipow>        |   __ipow__    | <Signature (a, b, /)> | ('a', 'b')
<built-in function irshift>     |    irshift    | <Signature (a, b, /)> | ('a', 'b')
<built-in function irshift>     |  __irshift__  | <Signature (a, b, /)> | ('a', 'b')
<built-in function is_>         |      is_      | <Signature (a, b, /)> | ('a', 'b')
<built-in function is_not>      |    is_not     | <Signature (a, b, /)> | ('a', 'b')
<built-in function isub>        |     isub      | <Signature (a, b, /)> | ('a', 'b')
<built-in function isub>        |   __isub__    | <Signature (a, b, /)> | ('a', 'b')
<built-in function itruediv>    |   itruediv    | <Signature (a, b, /)> | ('a', 'b')
<built-in function itruediv>    | __itruediv__  | <Signature (a, b, /)> | ('a', 'b')
<built-in function ixor>        |     ixor      | <Signature (a, b, /)> | ('a', 'b')
<built-in function ixor>        |   __ixor__    | <Signature (a, b, /)> | ('a', 'b')
<built-in function le>          |      le       | <Signature (a, b, /)> | ('a', 'b')
<built-in function le>          |    __le__     | <Signature (a, b, /)> | ('a', 'b')
<built-in function length_hint> |  length_hint  | <Signature (obj, default=0, /)> | ('obj', 'default')
<built-in function lshift>      |    lshift     | <Signature (a, b, /)> | ('a', 'b')
<built-in function lshift>      |  __lshift__   | <Signature (a, b, /)> | ('a', 'b')
<built-in function lt>          |      lt       | <Signature (a, b, /)> | ('a', 'b')
<built-in function lt>          |    __lt__     | <Signature (a, b, /)> | ('a', 'b')
<built-in function matmul>      |    matmul     | <Signature (a, b, /)> | ('a', 'b')
<built-in function matmul>      |  __matmul__   | <Signature (a, b, /)> | ('a', 'b')
<built-in function mod>         |      mod      | <Signature (a, b, /)> | ('a', 'b')
<built-in function mod>         |    __mod__    | <Signature (a, b, /)> | ('a', 'b')
<built-in function mul>         |      mul      | <Signature (a, b, /)> | ('a', 'b')
<built-in function mul>         |    __mul__    | <Signature (a, b, /)> | ('a', 'b')
<built-in function ne>          |      ne       | <Signature (a, b, /)> | ('a', 'b')
<built-in function ne>          |    __ne__     | <Signature (a, b, /)> | ('a', 'b')
<built-in function neg>         |      neg      | <Signature (a, /)>    | ('a',)
<built-in function neg>         |    __neg__    | <Signature (a, /)>    | ('a',)
<built-in function not_>        |     not_      | <Signature (a, /)>    | ('a',)
<built-in function not_>        |    __not__    | <Signature (a, /)>    | ('a',)
<built-in function or_>         |      or_      | <Signature (a, b, /)> | ('a', 'b')
<built-in function or_>         |    __or__     | <Signature (a, b, /)> | ('a', 'b')
<built-in function pos>         |      pos      | <Signature (a, /)>    | ('a',)
<built-in function pos>         |    __pos__    | <Signature (a, /)>    | ('a',)
<built-in function pow>         |      pow      | <Signature (a, b, /)> | ('a', 'b')
<built-in function pow>         |    __pow__    | <Signature (a, b, /)> | ('a', 'b')
<built-in function rshift>      |    rshift     | <Signature (a, b, /)> | ('a', 'b')
<built-in function rshift>      |  __rshift__   | <Signature (a, b, /)> | ('a', 'b')
<built-in function setitem>     |    setitem    | <Signature (a, b, c, /)> | ('a', 'b', 'c')
<built-in function setitem>     |  __setitem__  | <Signature (a, b, c, /)> | ('a', 'b', 'c')
<built-in function sub>         |      sub      | <Signature (a, b, /)> | ('a', 'b')
<built-in function sub>         |    __sub__    | <Signature (a, b, /)> | ('a', 'b')
<built-in function truediv>     |    truediv    | <Signature (a, b, /)> | ('a', 'b')
<built-in function truediv>     |  __truediv__  | <Signature (a, b, /)> | ('a', 'b')
<built-in function truth>       |     truth     | <Signature (a, /)>    | ('a',)
<built-in function xor>         |      xor      | <Signature (a, b, /)> | ('a', 'b')
<built-in function xor>         |    __xor__    | <Signature (a, b, /)> | ('a', 'b')

Best!
-- K2P

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions