Describe the bug
When importing or initializing any Litestar Controller utilizing create_filter_dependencies() or _build_before_after_provider on SQLSpec 0.47.0, the module crashes with:
UnboundLocalError: local variable "before_annotation" referenced before assignment
This regression occurs inside sqlspec/extensions/litestar/providers.py during instantiation of _BeforeAfterFilterProvider.
Cause / Analysis
The regression is caused by an optimization pass in MyPyC when compiling _BeforeAfterFilterProvider.__init__.
Under a pure-python fallback (e.g. removing the compiled .so module), _BeforeAfterFilterProvider instantiates perfectly. However, once compiled with MyPyC, the presence of two local variables ending in the same suffix _annotation (before_annotation and after_annotation) inside the constructor triggers a compiler/optimizer bug that loses local variable tracking, raising the UnboundLocalError at runtime.
Solution / Workaround
Renaming the variables to avoid the suffix clash resolves the MyPyC compilation bug completely:
- before_annotation = Annotated[DTorNone, QueryParameter(name=before_alias, required=False)]
- after_annotation = Annotated[DTorNone, QueryParameter(name=after_alias, required=False)]
+ before_ann = Annotated[DTorNone, QueryParameter(name=before_alias, required=False)]
+ after_ann = Annotated[DTorNone, QueryParameter(name=after_alias, required=False)]
self.signature = inspect.Signature(
parameters=[
inspect.Parameter(
- self.before_param, kind=inspect.Parameter.KEYWORD_ONLY, default=None, annotation=before_annotation
+ self.before_param, kind=inspect.Parameter.KEYWORD_ONLY, default=None, annotation=before_ann
),
inspect.Parameter(
- self.after_param, kind=inspect.Parameter.KEYWORD_ONLY, default=None, annotation=after_annotation
+ self.after_param, kind=inspect.Parameter.KEYWORD_ONLY, default=None, annotation=after_ann
),
],
return_annotation=BeforeAfterFilter,
)
self.annotations = {
- self.before_param: before_annotation,
- self.after_param: after_annotation,
+ self.before_param: before_ann,
+ self.after_param: after_ann,
"return": BeforeAfterFilter,
}
Describe the bug
When importing or initializing any Litestar Controller utilizing
create_filter_dependencies()or_build_before_after_provideron SQLSpec0.47.0, the module crashes with:This regression occurs inside
sqlspec/extensions/litestar/providers.pyduring instantiation of_BeforeAfterFilterProvider.Cause / Analysis
The regression is caused by an optimization pass in MyPyC when compiling
_BeforeAfterFilterProvider.__init__.Under a pure-python fallback (e.g. removing the compiled
.somodule),_BeforeAfterFilterProviderinstantiates perfectly. However, once compiled with MyPyC, the presence of two local variables ending in the same suffix_annotation(before_annotationandafter_annotation) inside the constructor triggers a compiler/optimizer bug that loses local variable tracking, raising theUnboundLocalErrorat runtime.Solution / Workaround
Renaming the variables to avoid the suffix clash resolves the MyPyC compilation bug completely: