Vorac
Vorac

Reputation: 9114

Python type hint on default parameter explodes

Without : int this program runs fine:

#!/usr/bin/env python3

import typing  # not needed

def foo():
    return (1,2,3)

def bar(i = foo()[0]: int):  # adding ': int' breaks the Universe
    return i

print(bar())

Upvotes: 1

Views: 51

Answers (1)

Zac Anger
Zac Anger

Reputation: 7747

You've got it backwards, the type hint goes after the param, not after the default:

def bar(i: int = foo()[0]):

Upvotes: 3

Related Questions