Skip to content

Commit 56204e8

Browse files
authored
Fix baseinvocation use of __attribute__ to work with py3.9 (#4413)
## What type of PR is this? (check all applicable) - [X] Bug Fix ## Have you discussed this change with the InvokeAI team? - [X] Yes ## Have you updated all relevant documentation? - [X] Yes ## Description There is a call in `baseinvocation.invocation_output()` to `cls.__annotations__`. However, in Python 3.9 not all objects have this attribute. I have worked around the limitation in the way described in https://docs.python.org/3/howto/annotations.html , which supposedly will produce same results in 3.9, 3.10 and 3.11. ## Related Tickets & Documents See https://discord.com/channels/1020123559063990373/1146897072394608660/1146939182300799017 for first bug report.
2 parents e27819f + f1a01c4 commit 56204e8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

invokeai/app/invocations/baseinvocation.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,9 @@ def wrapper(cls: Type[GenericBaseInvocation]) -> Type[GenericBaseInvocation]:
580580
config=cls.__config__,
581581
)
582582
cls.__fields__.update({"type": invocation_type_field})
583-
cls.__annotations__.update({"type": invocation_type_annotation})
584-
583+
# to support 3.9, 3.10 and 3.11, as described in https://docs.python.org/3/howto/annotations.html
584+
if annotations := cls.__dict__.get("__annotations__", None):
585+
annotations.update({"type": invocation_type_annotation})
585586
return cls
586587

587588
return wrapper
@@ -615,7 +616,10 @@ def wrapper(cls: Type[GenericBaseInvocationOutput]) -> Type[GenericBaseInvocatio
615616
config=cls.__config__,
616617
)
617618
cls.__fields__.update({"type": output_type_field})
618-
cls.__annotations__.update({"type": output_type_annotation})
619+
620+
# to support 3.9, 3.10 and 3.11, as described in https://docs.python.org/3/howto/annotations.html
621+
if annotations := cls.__dict__.get("__annotations__", None):
622+
annotations.update({"type": output_type_annotation})
619623

620624
return cls
621625

0 commit comments

Comments
 (0)