Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type annotation style (to space or not to space)

Tags:

python

pep

Having the following function:

def foo(x=1):
    print(x)

It is clearly stated in PEP 8 that no spaces should be used around the = sign when used to indicate a keyword argument or a default parameter value.

If we want to type-annotate the x parameter. How should we do it?

def foo(x:int=1):
def foo(x: int=1):
def foo(x: int = 1):

Is there a preferred way? Or even better, is it specified in some PEP? Did not find it in PEP 484.

like image 601
Peque Avatar asked May 11 '17 11:05

Peque


1 Answers

The examples in PEP 484 all use

def foo(x: int = 1):
like image 200
Nils Werner Avatar answered Nov 14 '22 16:11

Nils Werner