Skip to content

inspect.signature does not respect PEP 8 #76199

Closed

Description

@ilevkivskyi
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']

    Activity

    1. ilevkivskyi commented on Nov 13, 2017

      @ilevkivskyi
      MemberAuthor

      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.

    2. added
      3.7 (EOL)
      type-bug
      on Nov 13, 2017
    3. bitdancer commented on Nov 13, 2017

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

    4. gvanrossum commented on Nov 13, 2017

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

    5. bitdancer commented on Nov 13, 2017

      @bitdancer
      Member

      Agreed.

    6. corona10 commented on Nov 15, 2017

      @corona10
      Member

      I've submitted a patch. :)

    7. 1st1 commented on Nov 15, 2017

      @1st1
      Member

      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

    8. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)type-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions