If a variable X refers to a function in "module scope" and an integer in "function body scope", then the expression 1 + X will report a type error saying X has function type.
The expression X + 1 works fine.
Same things happen with the * binary operator.
Here's an example. The variable z is bound to a function in "module scope" and to an integer within the body of the function f. On the line marked ERROR, the typechecker (unsoundly) believes that z has type Function([], Int)
def z ()->int:
return 0
def f()->int:
z = 4
y = z + 1 # OK
x = 1 + z # ERROR
return 0
Error message:
====STATIC TYPE ERROR=====
bar.py:7:6: Int and Function([], Int) are invalid operand types for the binary operator +. (code BINOP_INCOMPAT)
If a variable
Xrefers to a function in "module scope" and an integer in "function body scope", then the expression1 + Xwill report a type error sayingXhas function type.The expression
X + 1works fine.Same things happen with the
*binary operator.Here's an example. The variable
zis bound to a function in "module scope" and to an integer within the body of the functionf. On the line markedERROR, the typechecker (unsoundly) believes thatzhas typeFunction([], Int)Error message: