🕯️ Magic Note
A class with pass is perfectly valid Python. You can instantiate it, assign attributes to its instances, and even add methods later through inheritance or monkey patching. The empty class is a blank canvas, not a broken one.
- pass works anywhere Python expects an indented block
- Empty classes are useful as simple data containers or type markers
- You can add attributes dynamically: brew.temperature = 75
- Can later add methods by defining them in the class or subclassing
| Pattern | Syntax | Use Case |
|---|---|---|
| Empty class | class Name: pass | Placeholder or simple container |
| Class with docstring | class Name: “””doc””” | Documented empty class |
| Class with pass later | class Name:\n pass | Future implementation planned |
| Instantiation | obj = Name() | Creating an object instance |
Python
# Creating an empty class and using it as a container
class Coffee:
pass
brew = Coffee()
brew.name = “Espresso”
brew.strength = 9
brew.temperature = 92
print(brew.name)
# Output: Espresso
Python
# Using empty class as a namespace or configuration holder
class Config:
pass
Config.THEME = “dark”
Config.FONT_SIZE = 16
Config.ANIMATIONS = True
print(Config.THEME)
# Output: dark
Python
# Empty class as a base for future expansion
class Spell:
pass
class FireSpell(Spell):
def cast(self):
return “🔥”
class IceSpell(Spell):
def cast(self):
return “❄️”
fire = FireSpell()
print(fire.cast())
# Output: 🔥
- Forgetting pass after an empty class declaration, causing an IndentationError
- Expecting empty classes to have predefined attributes, all attributes must be added manually
- Using pass when you actually need an init method with default values
⚡ Whisper
Every spell begins as an empty shape. The vessel exists before the liquid pours. Let your class breathe in silence at first. Life comes later. Form is the first magic.