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

Closed
ilevkivskyi opened this issue Nov 13, 2017 · 6 comments
Closed

inspect.signature does not respect PEP 8 #76199

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

Comments

@ilevkivskyi
Copy link
Member

BPO 32018
Nosy @gvanrossum, @ericvsmith, @bitdancer, @1st1, @ilevkivskyi, @corona10
PRs
  • 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 = 'https://github.com/ilevkivskyi'

    bugs.python.org 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 = 'https://bugs.python.org/issue32018'
    versions = ['Python 3.7']

    @ilevkivskyi
    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).

    Yes:

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

    No:

    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
    @bitdancer
    Copy link
    Member

    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 :)

    @gvanrossum
    Copy link
    Member

    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. :-)

    @bitdancer
    Copy link
    Member

    Agreed.

    @corona10
    Copy link
    Member

    I've submitted a patch. :)

    @1st1
    Copy link
    Member

    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)
    762b957

    @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
    Labels
    3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants