function types are understood in the restrictive sense, specifying:
foois declared to have a
fixnumargument, then the
(foo (1+ x))is compiled with knowledge that the result must be a fixnum.
ftypeimplicitly declares the types of the arguments in the definition. Python checks for consistency between the definition and the
ftypedeclaration. Because of precise type checking, an error will be signaled when a function is called with an argument of the wrong type.
fixnum, then when a call to that function appears in an expression, the expression will be compiled with knowledge that the call will return a
ftypedeclaration is treated like an implicit
thewrapped around the body of the definition. If the definition returns a value of the wrong type, an error will be signaled. If the compiler can prove that the function returns the wrong type, then it will give a compile-time warning.
This is consistent with the new interpretation of function types and
ftype declaration in the proposed X3J13
“function-type-argument-type-semantics” cleanup. Note also, that if
you don’t explicitly declare the type of a function using a global
ftype declaration, then Python will compute a function type
from the definition, providing a degree of inter-routine type
inference, see function-type-inference.