From dcb6706489dbaba1dbdb45368968ef6ebfde23a8 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 11 Dec 2024 22:22:26 -0500 Subject: [PATCH] Support `ctx: UnionType` annots for `@tractor.context` eps --- tractor/_context.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tractor/_context.py b/tractor/_context.py index 4a20c2b..d17f0b1 100644 --- a/tractor/_context.py +++ b/tractor/_context.py @@ -47,6 +47,9 @@ from functools import partial import inspect from pprint import pformat import textwrap +from types import ( + UnionType, +) from typing import ( Any, AsyncGenerator, @@ -2544,7 +2547,14 @@ def context( name: str param: Type for name, param in annots.items(): - if param is Context: + if ( + param is Context + or ( + isinstance(param, UnionType) + and + Context in param.__args__ + ) + ): ctx_var_name: str = name break else: