CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-asyncstdlib

The missing async toolbox - re-implements functions and classes of the Python standard library to make them compatible with async callables, iterables and context managers

84

3.36x

Quality

Pending

Does it follow best practices?

Impact

84%

3.36x

Average score across 10 eval scenarios

Overview
Eval results
Files

task.mdevals/scenario-10/

Data Analytics Metrics Calculator

Build a data analytics system that computes expensive metrics from datasets with proper caching to avoid redundant calculations.

Requirements

Create a MetricsCalculator class that:

  1. Accepts a dataset (list of numbers) upon initialization
  2. Provides three computed metrics as async properties:
    • mean: The average value of the dataset
    • variance: The variance of the dataset
    • std_dev: The standard deviation of the dataset
  3. Each metric computation should include a small async delay (e.g., 0.1 seconds) to simulate an expensive operation
  4. Each metric should be computed only once and cached for subsequent accesses
  5. When multiple coroutines access an uncached property concurrently, the computation should happen only once
  6. Cached values can be invalidated using del (e.g., del calculator.mean), after which the next access recomputes the value

Implementation

@generates

API

class MetricsCalculator:
    """
    A class that computes statistical metrics from a dataset with caching.
    """

    def __init__(self, data: list[float]):
        """
        Initialize the calculator with a dataset.

        Args:
            data: A list of numeric values to analyze
        """
        pass

    async def mean(self) -> float:
        """
        Calculate and cache the mean of the dataset.

        Returns:
            The mean (average) value
        """
        pass

    async def variance(self) -> float:
        """
        Calculate and cache the variance of the dataset.

        Returns:
            The variance value
        """
        pass

    async def std_dev(self) -> float:
        """
        Calculate and cache the standard deviation of the dataset.

        Returns:
            The standard deviation value
        """
        pass

Test Cases

  • The mean property returns the correct average value for a given dataset @test
  • The variance property returns the correct variance value for a given dataset @test
  • The std_dev property returns the correct standard deviation value for a given dataset @test
  • Accessing the same property multiple times returns cached results without recomputation @test
  • Concurrent access to the same uncached property computes the value only once @test
  • Deleting a cached property and accessing it again triggers recomputation @test

Dependencies { .dependencies }

asyncstdlib { .dependency }

Provides async-compatible standard library functions including cached property support.

Install with Tessl CLI

npx tessl i tessl/pypi-asyncstdlib

tile.json