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

inspect.signature does not respect PEP 8 #76199

ilevkivskyi opened this issue Nov 13, 2017 · 6 comments

inspect.signature does not respect PEP 8 #76199

ilevkivskyi opened this issue Nov 13, 2017 · 6 comments
3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error


Copy link

BPO 32018
Nosy @gvanrossum, @ericvsmith, @bitdancer, @1st1, @ilevkivskyi, @corona10
  • bpo-32018: inspect.signature should follow PEP 8 #4408
  • 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 = <Date 2017-11-15.18:31:22.405>
    created_at = <Date 2017-11-13.22:06:50.739>
    labels = ['type-bug', '3.7']
    title = 'inspect.signature does not respect PEP 8'
    updated_at = <Date 2017-11-15.18:31:22.404>
    user = '' fields:

    activity = <Date 2017-11-15.18:31:22.404>
    actor = 'yselivanov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-11-15.18:31:22.405>
    closer = 'yselivanov'
    components = []
    creation = <Date 2017-11-13.22:06:50.739>
    creator = 'levkivskyi'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32018
    keywords = ['patch']
    message_count = 6.0
    messages = ['306171', '306172', '306174', '306175', '306295', '306296']
    nosy_count = 6.0
    nosy_names = ['gvanrossum', 'eric.smith', 'r.david.murray', 'yselivanov', 'levkivskyi', 'corona10']
    pr_nums = ['4408']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = ''
    versions = ['Python 3.7']

    Copy link
    Member Author

    The string representation of a function signature with annotations is currently like this:

    >>> def __init__(self, x: int = 1, y: int = 2) -> None: pass
    >>> import inspect
    >>> str(inspect.signature(__init__))
    '(self, x:str=1, y:int=2) -> None'

    At the same time PEP-8 says:

    When combining an argument annotation with a default value, use spaces around the = sign (but only for those arguments that have both an annotation and a default).


    def munge(sep: AnyStr = None): ...
    def munge(input: AnyStr, sep: AnyStr = None, limit=1000): ...


    def munge(input: AnyStr=None): ...
    def munge(input: AnyStr, limit = 1000): ...

    I think there should be spaces in the signature repr.

    @ilevkivskyi ilevkivskyi added 3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error labels Nov 13, 2017
    Copy link

    FWIW, I find the version without the spaces to be more readable (but I don't find annotations to be readable in general, so my opinion may not be worth much :)

    Copy link

    Those people who read and write annotations regularly are all using the convention that was added to PEP-8, so let's make inspect follow that lead rather than argue about it here. :-)

    Copy link


    Copy link

    I've submitted a patch. :)

    Copy link

    1st1 commented Nov 15, 2017

    New changeset 762b957 by Yury Selivanov (Dong-hee Na) in branch 'master':
    bpo-32018: Fix inspect.signature repr to follow PEP-8 (bpo-4408)

    @1st1 1st1 closed this as completed Nov 15, 2017
    @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
    3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error
    None yet

    No branches or pull requests

    5 participants