Skip to content

Commit a33be0a

Browse files
committed
Catch NameError for adamghill#639.
1 parent dbd1e4e commit a33be0a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

django_unicorn/typer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def get_type_hints(obj) -> Dict:
7878
type_hints_cache[obj] = type_hints
7979

8080
return type_hints
81-
except TypeError:
81+
except (TypeError, NameError):
8282
# Return an empty dictionary when there is a TypeError. From `get_type_hints`: "TypeError is
8383
# raised if the argument is not of a type that can contain annotations, and an empty dictionary
8484
# is returned if no annotations are present"

tests/test_typer.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import datetime
12
from typing import Optional
23
from typing import get_type_hints as typing_get_type_hints
34

5+
from django_unicorn.components import UnicornView
46
from django_unicorn.typer import cast_attribute_value, cast_value, get_type_hints
57
from example.coffee.models import Flavor
68

@@ -23,6 +25,15 @@ def test_func(input_str):
2325
assert actual == expected
2426

2527

28+
def test_get_type_hints_gh_639():
29+
class MyComponentView(UnicornView):
30+
a_date: datetime.date
31+
32+
expected = {"a_date": datetime.date}
33+
actual = get_type_hints(MyComponentView(component_name="test", component_id="123"))
34+
assert actual == expected
35+
36+
2637
class TestClass:
2738
integer: int
2839
boolean: bool

0 commit comments

Comments
 (0)