Skip to content

Commit

Permalink
Catch NameError for #639.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamghill committed Jan 4, 2024
1 parent 1525c99 commit ffb64f2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django_unicorn/typer.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def get_type_hints(obj) -> Dict:
type_hints_cache[obj] = type_hints

return type_hints
except TypeError:
except (TypeError, NameError):
# Return an empty dictionary when there is a TypeError. From `get_type_hints`: "TypeError is
# raised if the argument is not of a type that can contain annotations, and an empty dictionary
# is returned if no annotations are present"
Expand Down
12 changes: 12 additions & 0 deletions tests/test_typer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import datetime
from typing import Optional
from typing import get_type_hints as typing_get_type_hints

from django_unicorn.components import UnicornView
from django_unicorn.typer import cast_attribute_value, cast_value, get_type_hints
from example.coffee.models import Flavor

Expand All @@ -23,6 +25,16 @@ def test_func(input_str):
assert actual == expected



def test_get_type_hints_gh_639():
class MyComponentView(UnicornView):
a_date: datetime.date

expected = {"a_date": datetime.date}
actual = get_type_hints(MyComponentView(component_name="test", component_id="123"))
assert actual == expected


class TestClass:
integer: int
boolean: bool
Expand Down

0 comments on commit ffb64f2

Please sign in to comment.