Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

Commit ca4fb6b

Browse files
committed
util: python: is_forward_ref_dataclass: Helper to check for ForwardRef or str
Related: python/cpython#21553 (comment) Signed-off-by: John Andersen <johnandersenpdx@gmail.com>
1 parent c14980e commit ca4fb6b

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

dffml/util/python.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ def within_method(obj: object, method_name: str, max_depth: int = -1) -> bool:
182182
return False
183183

184184

185+
def is_forward_ref_dataclass(dataclass, type_cls):
186+
"""
187+
Check if a field's type is a ForwardRef, either via being an instance, or
188+
being a type which is a string. An instance of a string is not a type,
189+
therefore if we see a string, we should assume it is a ForwardRef.
190+
"""
191+
return isinstance(type_cls, (ForwardRef, str))
192+
193+
185194
def resolve_forward_ref_dataclass(dataclass, type_cls):
186195
"""
187196
>>> import dataclasses

0 commit comments

Comments
 (0)