Skip to content
Sarj Code Standards

no-nullable-dependency-fallback

Require concrete function dependencies instead of resolving a None default inside the function.

Why

A None dependency silently selects another implementation or ambient configuration, hiding wiring mistakes and adding unnecessary branches.

Fix

Give a dependency a required type when production wiring always supplies it. Tests can supply an empty implementation. Keep the type nullable when absence disables an operation. Resolve fallback implementations at the call site, or use a concrete callable default when its lifetime is appropriate.

Examples

Before — flagged Omission silently selects an implementation
app/service.py
def run(factory: Factory | None = None):
return (factory or DefaultFactory)()
After — preferred The caller supplies a factory and can disable notifications
app/service.py
def run(factory: Factory):
return factory()
def notify(sender: Sender | None, message: str):
if sender is not None:
sender.send(message)