Why This Happens
Instance attributes are created by assignment with self.attr = value in __init__. If you forget self, you create a local variable. If __init__ conditionally sets attributes, some instances may lack them.
The Problem
class Counter:
def __init__(self, start):
count = start # Missing self!
def increment(self):
self.count += 1The Fix
class Counter:
def __init__(self, start):
self.count = start
def increment(self):
self.count += 1Step-by-Step Fix
- 1
Check __init__ for self
Verify all attribute assignments use self.attribute = value.
- 2
Check for typos
Ensure the attribute name in __init__ matches the name used elsewhere.
- 3
Initialize all attributes
Set default values for all attributes in __init__.
Bugsly catches this automatically
Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.
Try Bugsly free