Python supercharged for fastai development
56
Build a flexible configuration manager that supports nested attribute access, delegation to a default configuration, and automatic attribute storage from initialization parameters.
Create a configuration manager system with the following components:
Implement a Config class that:
get_nested(path) that retrieves values from nested attributes using a dot-separated path stringhas_nested(path) that checks if nested attributes exist using a dot-separated path stringImplement a ConfigWithDefaults class that:
get_attrs(attr_list) that retrieves multiple attributes at once, returning them as a tupleWhen Config is initialized with host="localhost" and port=5432, accessing config.host returns "localhost" and config.port returns 5432 @test
When a nested dict structure is stored in Config (e.g., db={"host": "localhost", "port": 5432}), calling get_nested("db.host") returns "localhost" @test
When checking if a nested path exists using has_nested("db.port") on a config with nested structure, it returns True if the path exists and False otherwise @test
When ConfigWithDefaults is initialized with user config having host="custom" and default config having host="localhost" and timeout=30, accessing config.host returns "custom" and config.timeout returns 30 @test
When calling get_attrs(["host", "timeout"]) on a ConfigWithDefaults instance, it returns a tuple with both values, pulling from user config or defaults as appropriate @test
@generates
class Config:
"""Configuration class with automatic attribute storage and nested access."""
def __init__(self, **kwargs):
"""Initialize with keyword arguments stored as attributes."""
pass
def get_nested(self, path: str):
"""Get a nested attribute using dot notation (e.g., 'db.host')."""
pass
def has_nested(self, path: str) -> bool:
"""Check if a nested attribute exists using dot notation."""
pass
class ConfigWithDefaults:
"""Configuration that delegates to defaults when attributes are not found."""
def __init__(self, user_config, default_config):
"""Initialize with user config and default config for delegation."""
pass
def get_attrs(self, attr_list: list) -> tuple:
"""Get multiple attributes at once, returning them as a tuple."""
passProvides utilities for attribute access, delegation, and functional programming.
Install with Tessl CLI
npx tessl i tessl/pypi-fastcoredocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10