Skip to content

strategies.py: strategy_features() silently accepts any unrecognized strategy name #418

Description

@yakew7

Where: faircode/strategies.py:97-102 (strategy_features).

The gap:

def strategy_features(strategy: str, core: list, proxies: list, protected: list) -> list:
    if strategy == "baseline":
        return list(dict.fromkeys(core + proxies + protected))
    if strategy == "unawareness":
        return list(dict.fromkeys(core + proxies))
    return list(core)  # unawareness_proxy_removal, in_processing, post_processing

The final return list(core) is a bare else in practice - it's meant to handle exactly the three strategies named in its comment, but any unrecognized string (a typo like "in_procesing") silently falls into the same branch instead of raising.

Repro:

>>> from faircode.strategies import strategy_features
>>> strategy_features("in_procesing", ["a"], ["b"], ["c"])   # typo'd
['a']

No error - returns exactly the same result as a genuinely recognized "core-only" strategy.

Why it matters: faircode/benchmark.py only ever iterates the fixed STRATEGIES tuple today, so this isn't reachable through the CLI/normal benchmark run - but strategy_features is a public-enough function (imported directly, no leading underscore) that anyone calling it from a notebook, script, or future extension gets a silent wrong-but-plausible answer for a typo'd strategy name instead of an error. tests/test_strategies.py has no "unknown strategy" test.

Suggested fix: add an explicit else: raise ValueError(f"unknown strategy: {strategy!r}") instead of the bare fallback.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions