TypeError: ‘X’ object is not callable
- module
- callable
- shadowing
- list
Perhaps most commonly, this manifests as 'module' object is not callable although you see it with all built-in types from time to time.
For 'module', a common cause is having a module with a surprising import. If you
import foo
and expect my_foo = foo() to work but it requires something like my_foo = foo.foo() instead, that’s where you are trying to call a module which isn’t callable.
For other types, a common case is when you trampled your own variable somewhere. Perhaps you did
def my_number(): ...
and then later on
my_number = 42
which replaces the function with a simple int. Now, my_number() is no longer valid, because 'int' object is not callable.
Something similar will also occur if you use a builtin name for a variable. If you do
str = 'hello'
you will cause 'str' object is not callable for anything which subsequently tries to use the built-in str type in this scope, like this:
x = str(5)