55 Any ,
66 Generic ,
77 TypeVar ,
8- cast ,
98 overload ,
109)
1110
12- from django .db .models import Model
13-
1411from . import baker
1512from ._types import M
1613from .exceptions import RecipeNotFound
@@ -178,19 +175,19 @@ def extend(self: _T, **attrs: Any) -> _T:
178175 return type (self )(self ._model , ** attr_mapping )
179176
180177
181- def _load_recipe_from_calling_module (recipe : str ) -> Recipe [Model ]:
178+ def _load_recipe_from_calling_module (recipe_name : str ) -> Recipe [Any ]:
182179 """Load `Recipe` from the string attribute given from the calling module.
183180
184181 Args:
185- recipe (str): the name of the recipe attribute within the module from
182+ recipe_name (str): the name of the recipe attribute within the module from
186183 which it should be loaded
187184
188185 Returns:
189186 (Recipe): recipe resolved from calling module
190187 """
191- recipe = getattr (get_calling_module (2 ), recipe )
188+ recipe = getattr (get_calling_module (2 ), recipe_name )
192189 if recipe :
193- return cast ( Recipe [ Model ], recipe )
190+ return recipe
194191 else :
195192 raise RecipeNotFound
196193
@@ -217,16 +214,19 @@ def foreign_key(
217214 This resolves recipes supplied as strings from other module paths or from
218215 the calling code's module.
219216 """
217+ resolved_recipe : Recipe [M ]
220218 if isinstance (recipe , str ):
221219 # Load `Recipe` from string before handing off to `RecipeForeignKey`
222220 try :
223221 # Try to load from another module
224- recipe = baker ._recipe (recipe )
222+ resolved_recipe = baker ._recipe (recipe )
225223 except (AttributeError , ImportError , ValueError ):
226224 # Probably not in another module, so load it from calling module
227- recipe = _load_recipe_from_calling_module (cast (str , recipe ))
225+ resolved_recipe = _load_recipe_from_calling_module (recipe )
226+ else :
227+ resolved_recipe = recipe
228228
229- return RecipeForeignKey (cast ( Recipe [ M ], recipe ) , one_to_one )
229+ return RecipeForeignKey (resolved_recipe , one_to_one )
230230
231231
232232class related (Generic [M ]): # FIXME
0 commit comments