[Python-Dev] FunctionDef.returns - explicit 'None' return type hint

2017-01-19 Thread Valentin Iovene via Python-Dev
With a ast.FunctionDef ast.AST node, is it possible to make the
difference between this function

def hello_world():
print('hello world')

and this one

def hello_world() -> None:
print('hello world')

?

In both cases, the FunctionDef node has its 'returns' (return type
hint) attribute set to None.

-- 
Valentin
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] FunctionDef.returns - explicit 'None' return type hint

2017-01-19 Thread Valentin Iovene via Python-Dev
> >>> t = compile('def f(): pass', '', 'exec', ast.PyCF_ONLY_AST)
> >>> print(t.body[0].returns)
> None
> >>> t = compile('def f() -> None: pass', '', 'exec', ast.PyCF_ONLY_AST)
> >>> print(t.body[0].returns)
> <_ast.NameConstant object at 0x10a900f28>
> >>>  print(t.body[0].returns.value)
> None

My bad, thank you my King. ;)

-- 
Valentin
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com