@@ -397,7 +397,8 @@ def parse_ingredients(
397397
398398 if not api_version .startswith ("v3" ):
399399 logger .warning (
400- "ingredient parsing is only available in v3 of the API (here: %s), using v3" ,
400+ "ingredient parsing is only available in v3 of the API (here: %s), "
401+ "using v3" ,
401402 self .api_config .version ,
402403 )
403404 api_version = "v3"
@@ -431,11 +432,12 @@ def parse_ingredients(
431432 ) as e :
432433 raise RuntimeError (
433434 f"Unable to parse ingredients: error during HTTP request: { e } "
434- )
435+ ) from e
435436
436437 if not r .ok :
437438 raise RuntimeError (
438- f"Unable to parse ingredients (non-200 status code): { r .status_code } , { r .text } "
439+ "Unable to parse ingredients (non-200 status code): "
440+ f"{ r .status_code } , { r .text } "
439441 )
440442
441443 response_data = r .json ()
@@ -486,8 +488,9 @@ def upload_image(
486488 api_version = self .api_config .version
487489 if not self .api_config .version .startswith ("v3" ):
488490 warnings .warn (
489- "image upload is only available in v3 of the API (here: %s), forcing use of v3"
490- % self .api_config .version ,
491+ "image upload is only available in v3 of the API (here: %s), "
492+ "forcing use of v3" % self .api_config .version ,
493+ stacklevel = 2 ,
491494 )
492495 api_version = "v3"
493496
@@ -534,7 +537,8 @@ def upload_image(
534537 )
535538 if not isinstance (value , dict ):
536539 raise ValueError (
537- f"selected[{ key } ][{ lang_code } ] must be a dict, got { type (value )} "
540+ f"selected[{ key } ][{ lang_code } ] must be a dict, got "
541+ f"{ type (value )} "
538542 )
539543
540544 # copy the config but force v3 of the API
@@ -665,11 +669,12 @@ def parse_ingredients(text: str, lang: str, api_config: APIConfig) -> list[JSONT
665669 ) as e :
666670 raise RuntimeError (
667671 f"Unable to parse ingredients: error during HTTP request: { e } "
668- )
672+ ) from e
669673
670674 if not r .ok :
671675 raise RuntimeError (
672- f"Unable to parse ingredients (non-200 status code): { r .status_code } , { r .text } "
676+ "Unable to parse ingredients (non-200 status code): "
677+ f"{ r .status_code } , { r .text } "
673678 )
674679
675680 response_data = r .json ()
0 commit comments