903 B
903 B
Evaluation tardive
Introduction
class A:
def function(self):
return A()
a = A()
A = int
print(f"{a.function() = }")
a.function() = 0
Explications
- Le code contenu dans une fonction n'est exécuté uniquement lorsque celle-ci est invoquée. Ainsi, la référence à la
fonction non déclarée A
par la méthode A.function
ne génère pas d'erreur,
- Durant l'exécution de la méthode
A.function
,
However, during the execution Python will bind the name A from the outer scope, which means that function method will return a newly created int instance.