object() in Python 2026: Base Class & Minimal Instance Creation + Modern Use Cases
The built-in object() is the most fundamental class in Python — every class inherits from it by default if no other base class is specified. Calling object() creates a plain, empty instance with no attributes or methods beyond those defined in object itself. In 2026 it remains the go-to base class for minimal objects, sentinel values, type annotations, metaprogramming, and as a safe starting point when you want no inherited behavior except the basics (__str__, __repr__, __eq__, etc.).
With Python 3.12–3.14+ improving object creation speed, enhancing free-threading safety for simple instances, and better type system support (Self, TypeGuard), object() is still the lightest possible object you can create. This March 24, 2026 update covers how object() behaves today, real-world patterns (sentinels, base classes, minimal mocks), performance notes, and best practices for using it in modern, type-safe Python code.
TL;DR — Key Takeaways 2026
object()→ creates a minimal instance with only object methods- Default base class for all user-defined classes if no parent is specified
- 2026 best practice: Use object() as explicit base for clean hierarchy; use instances as sentinels or minimal mocks
- Main use cases: sentinel values, base class in inheritance chains, lightweight placeholders, testing mocks
- Performance: Extremely lightweight — smallest possible object footprint
1. Basic Usage — Creating Minimal Objects
o = object()
print(type(o)) #
print(dir(o)) # ['__class__',
# '__delattr__',
# '__dir__',
# ...,
# '__str__']
print(hasattr(o, "x")) # False
o.x = 10 # can still add attributes dynamically
print(o.x) # 10
2. Real-World Patterns in 2026
Sentinel Values (Unique Markers)
MISSING = object() # unique sentinel — guaranteed not equal to any real value
def get_setting(key: str, default=MISSING):
if key in settings:
return settings[key]
if default is MISSING:
raise KeyError(f"Setting {key} not found")
return default
Minimal Base Class / Clean Inheritance
class Base:
pass # implicitly inherits from object
# Explicit minimal base (cleaner intent)
class MinimalBase(object):
pass
class MyClass(MinimalBase):
def __init__(self):
super().__init__()
Lightweight Mock / Placeholder Objects in Tests
def test_feature(mock_obj = object()):
# Minimal object with no side effects
if hasattr(mock_obj, "method"):
mock_obj.method()
else:
print("No method — using fallback")
3. object() vs Alternatives – Comparison 2026
| Approach | Size / Overhead | Methods | Best For |
|---|---|---|---|
| object() | Minimal (~48 bytes) | Only object methods | Sentinels, minimal bases |
| type("Sentinel", (), {}) | Small | Only object methods | Custom sentinel with name |
| object.__new__(object) | Minimal | Only object methods | Low-level creation |
| Simple class with pass | Small | object methods + __dict__ | When you need __dict__ |
4. Best Practices & Performance in 2026
- Use object() for sentinels — guaranteed unique & minimal footprint
- Explicit base class — inherit from object() for clarity in new-style classes
- Type hints 2026:
from typing import Any def is_sentinel(obj: Any) -> bool: return obj is MISSING MISSING = object() - Performance: object() creation is extremely lightweight — smallest possible object
- Free-threading (3.14+): Safe — immutable structure, no shared mutable state
Conclusion — object() in 2026: Minimal & Foundational
object() is the root of Python’s type hierarchy and the lightest possible object you can create. In 2026, use it for unique sentinels, explicit base classes, minimal mocks, and as a safe starting point for inheritance. It’s fast, memory-efficient, and one of Python’s most fundamental building blocks — essential for clean, predictable, and performant object-oriented code.
Next steps:
- Use object() as a sentinel in your next optional-value function
- Related articles: Efficient Python Code 2026 • Python Built-ins Overview 2026