A Closer Look At UnannotatedEmptyCollection False

by Jule 50 views
A Closer Look At UnannotatedEmptyCollection False

When optional parameters use a type alias like Hash[untyped, untyped], Steep flags {} as UnannotatedEmptyCollection - but only on that exact parameter. Direct use of Hash[untyped, untyped] triggers the same warning, even if tighter typing exists elsewhere. This quirk often trips developers expecting smarter type checking.nnThe real insight: type aliases don’t enforce runtime behavior. A default {} with Hash[untyped, untyped] is considered valid Ruby, so no annotation is needed. Parameters b, c, and d avoid the warning because their defaults are explicitly Hash[untyped, untyped] - tightly typed and no ambiguity.nnHere’s what’s actually happening:

  • The type alias resolves at call time, but Steep’s annotation system treats all defaults as unannotated unless explicitly marked.
  • Direct parameter use includes the full type, making it unambiguous.
  • The warning fades with explicit Hash[untyped, untyped] - proving Ruby’s type aliases don’t carry semantic weight.nnBut is this safe? Not really. Relying on Steep’s false positive risks missing real errors in complex collections. When working with type aliases, treat defaults as ambiguous until annotated. Always validate user input - even empty hashes can hide bugs. Are you sure an empty default is safe? The answer might surprise you.