Automation · Python Automation
Classes
Cheat sheet · https://pcornel.dk/topic.php?topic=5260
Answer
Python classes bundle data and methods into objects, such as a Device class with connect() and backup() methods, making larger automation easier to structure and test.
Remember
- Classes bundle data and methods.
- They make larger automation easier to test.
- Avoid classes for trivial scripts.
First checks
python3 -c 'import m; help(m.MyClass)'— class docsmypy .— type checking- Dataclasses/pydantic models — data structures
Verify in this order
class → instances → methods
Where it usually breaks
Input/desired state → request accepted → job/task terminal status → target object read-back → effective runtime state → original workload → regression/rollback readiness.
Python Automation → Classes · operational reference
| Layer | Python Automation → Classes operational reference |
|---|---|
| Runtime/ownership | Python class-based automation code · the Python interpreter and object model binding class definitions, instances, attributes, methods and inheritance at runtime |
| Persistent intent | version-controlled class contracts defining constructor inputs, instance state, public methods, invariants and composition/inheritance boundaries |
| Verification | Instantiate the class with a deterministic fixture, assert instance/class attribute behavior and method results, then exercise one mocked or sandboxed external side effect and verify the target separately. |
| Expected interpretation | Instances preserve their own valid state, inheritance/composition resolves the intended methods, failures surface at the correct boundary, and any external mutation is attributable and independently verifiable. |
| Recovery boundary | capture inputs and object/external IDs, reproduce with a minimal instance, fix the class contract at the narrowest layer, then rerun unit/fixture tests and independent external read-back |
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5260