Issue 32018: inspect.signature does not respect PEP 8 (original) (raw)

Issue32018

Created on 2017-11-13 22:06 by levkivskyi, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 4408 merged corona10,2017-11-15 17:36
Messages (6)
msg306171 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2017-11-13 22:06
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.
msg306172 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-11-13 22:11
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 :)
msg306174 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2017-11-13 22:49
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. :-)
msg306175 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-11-13 22:53
Agreed.
msg306295 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2017-11-15 18:25
I've submitted a patch. :)
msg306296 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2017-11-15 18:31
New changeset 762b9571c9c8c6b036f1bf90140a1d030b3f9a01 by Yury Selivanov (Dong-hee Na) in branch 'master': bpo-32018: Fix inspect.signature repr to follow PEP 8 (#4408) https://github.com/python/cpython/commit/762b9571c9c8c6b036f1bf90140a1d030b3f9a01
History
Date User Action Args
2022-04-11 14:58:54 admin set github: 76199
2017-11-15 18:31:22 yselivanov set status: open -> closedresolution: fixedstage: patch review -> resolved
2017-11-15 18:31:06 yselivanov set messages: +
2017-11-15 18:25:51 corona10 set messages: +
2017-11-15 17:46:28 corona10 set nosy: + corona10
2017-11-15 17:36:41 corona10 set keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest4357>
2017-11-13 22:53:52 r.david.murray set messages: +
2017-11-13 22:49:59 gvanrossum set nosy: + gvanrossummessages: +
2017-11-13 22:36:06 eric.smith set nosy: + eric.smith
2017-11-13 22:11:27 r.david.murray set nosy: + r.david.murraymessages: +
2017-11-13 22:06:50 levkivskyi create