'staticmethod' object is not callable
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
The error "'staticmethod' object is not callable" appears when Python code tries to call the staticmethod descriptor itself instead of the function bound through class attribute access. This usually happens when decorators are stacked incorrectly or when a method is accessed through __dict__ and bypasses descriptor behavior. The fix is to call the method through the class or instance name and verify decorator placement.
What @staticmethod Actually Does
@staticmethod wraps a function in a descriptor object. When you access MyClass.method, Python resolves the descriptor and returns the original function without injecting self or cls. If you access the raw descriptor directly, you get a staticmethod object, which is not directly callable.
Both calls work because descriptor resolution happens through normal attribute access.
A common failure path is touching __dict__ directly.
In ordinary application code, avoid raw descriptor access unless you are doing introspection tooling.
Correct Decorator Order and Method Access
Decorator order matters when combining @staticmethod with custom decorators. If your decorator expects a function but receives a descriptor, it can break callability.
If you reverse incompatible decorators, the wrapped object may no longer behave as expected. Keep unit tests around decorator-heavy utilities so refactors do not silently change call semantics.
Choosing Between Static, Class, and Instance Methods
Use @staticmethod when logic belongs conceptually to a class namespace but does not need instance or class state. If method behavior depends on class-level configuration, use @classmethod instead. If method needs object state, use normal instance methods.
Selecting the right method type reduces confusion and eliminates many descriptor-related bugs.
Testing Patterns That Catch Descriptor Mistakes
Descriptor bugs often appear only after refactoring, so automated tests are the best safety net. Write tests that call methods through class access and instance access, and add one introspection test if your framework inspects class dictionaries. This prevents future edits from silently changing call behavior.
These tests document intended behavior and make decorator regressions obvious during continuous integration.
Common Pitfalls
- Calling descriptors pulled from
__dict__directly instead of using attribute access. - Applying decorators in an order that passes a
staticmethoddescriptor where a function is expected. - Using
@staticmethodfor behavior that actually needs class configuration. - Renaming methods without updating tests that validate call paths.
- Overusing static methods for unrelated utility logic better placed in separate modules.
Summary
@staticmethodcreates a descriptor resolved through class or instance attribute access.- The raw
staticmethodobject is not the callable function you want. - Use normal access like
MyClass.method()for reliable behavior. - Validate decorator order when stacking custom wrappers with
@staticmethod. - Pick static, class, or instance methods based on required state access.
Related reading
- Step-by-step debugging with IPython
- Stop pip from failing on single package when installing with requirements.txt
- Stop Tensorflow from printing to the console
- Stopping/Purging Periodic Tasks in Django-Celery
- Status bar could not find cached time string image. Rendering in-process
- stdfind 'error no matching function
- Store output of subprocess.Popen call in a string
- Storing Python dictionaries
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.