- Home
- Skills
- Copyleftdev
- Sk1llz
- Ramalho
ramalho_skill
- Python
3
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill copyleftdev/sk1llz --skill ramalho- SKILL.md7.5 KB
Overview
This skill teaches how to write Python code in the style of Luciano Ramalho (author of Fluent Python), focusing on idiomatic, data-model-driven design. It emphasizes special methods, protocols, and advanced idioms so your objects integrate naturally with Python’s syntax and built-ins. Use it to make code clearer, more predictable, and more powerful by leveraging Python’s core abstractions.
How this skill works
The skill inspects design choices and suggests implementations that follow Ramalho’s principles: implement the right special methods, choose appropriate protocols (iterable, mapping, sequence, callable), and prefer structural patterns like descriptors, dataclasses, and collections. It recommends concrete method signatures and code patterns (e.g., __iter__, __repr__, __hash__, context managers) and explains trade-offs such as mutability vs. hashability. It outputs small, focused examples and refactor suggestions that make objects play well with Python’s language features.
When to use it
- Designing custom container or sequence types
- Creating domain objects that should interoperate with Python built-ins
- Refactoring classes to follow protocols and reduce surprises
- Adding computed attributes, validation, or lazy iteration
- Implementing context managers, descriptors, or operator overloading
Best practices
- Start by choosing the protocol your object should support, then implement the minimal special methods to enable it
- Implement __repr__ for unambiguous debugging and __str__ for user-friendly display
- Prefer collections.abc base classes and @dataclass for common patterns to reduce boilerplate
- Respect immutability when making objects hashable; avoid mutable __hash__ implementations
- Use descriptors for attribute validation and @contextmanager or class-based context managers where appropriate
Example use cases
- Build a numeric Vector that supports arithmetic, abs(), and boolean checks via __add__, __abs__, __bool__
- Create an efficient Sentence iterable with __iter__, __len__, and __getitem__ for slicing and membership
- Implement a validated Order class using descriptors for price/quantity checks
- Refactor a resource wrapper into a context manager to ensure deterministic cleanup
- Define Protocol interfaces (Drawable, Serializable) to enable duck-typed APIs with type hints
FAQ
No. Implement only the methods required by the protocol you need. Extra methods add maintenance cost and potential inconsistency.
When is it safe to make a class hashable?
Only if the object is effectively immutable for its hash-relevant attributes. If state used in __eq__ can change, do not implement __hash__.