Skip to content

Commit 86e0a82

Browse files
committed
Make ensure_annotations handle conditional defs
1 parent 18adcdb commit 86e0a82

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

_misc/_ensure_annotations.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import ast
1818
import inspect
1919
import sys
20+
import textwrap
2021
from functools import partial
2122
from types import FunctionType
2223
from typing import Any
@@ -39,7 +40,7 @@ def ensure_annotations[T: type | FunctionType](f: T) -> T:
3940
if _cycle_blocked:
4041
return f
4142

42-
new_ast = rec(ast.parse(inspect.getsource(f)), optimize=1)
43+
new_ast = rec(ast.parse(textwrap.dedent(inspect.getsource(f))), optimize=1)
4344

4445
env = sys.modules[f.__module__].__dict__
4546

0 commit comments

Comments
 (0)