Skip to content

[False Positive]: Dead code reported for dynamically registered handler #27

@orenlab

Description

@orenlab

CodeClone version

2.0.0

Detection family

Function clone

Minimal reproduction

# registry.py
REGISTRY = {}

def register(name):
    def wrapper(fn):
        REGISTRY[name] = fn
        return fn
    return wrapper

# handlers.py
from registry import register

@register("handler_a")
def handler_a():
    print("A")

# runtime.py
from registry import REGISTRY

def run(name: str):
    fn = REGISTRY.get(name)
    if fn:
        fn()

Why these should NOT be considered clones?

Why these should NOT be considered clones?

The reported dead code is actually reachable at runtime via a registry pattern:

  • the function is registered through a decorator
  • the decorator mutates shared state (REGISTRY)
  • invocation happens indirectly via a lookup (REGISTRY[name])

This pattern is intentionally dynamic and does not produce explicit call edges
in the static control flow graph.

From a semantic perspective:

  • the function is part of the executable behavior
  • it has externally observable side effects
  • removing it breaks runtime functionality

This appears to be a limitation of static reachability rather than unused code.

Additional signals

  • Control flow structure differs meaningfully
  • Side effects or runtime behavior differ meaningfully
  • The issue appears only in tests / fixtures

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinginvalidThis doesn't seem right

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions