File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed
Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change 22import sys
33from enum import Enum
44
5- from typing import List , Set , Dict
5+ from typing import List , Set , Dict , Union
66
77try :
88 from typing import _ForwardRef as ForwardRef
@@ -127,6 +127,12 @@ def is_typing_dict_annotation(annotation):
127127 return False
128128
129129
130+ def is_union_annotation (annotation ) -> bool :
131+ if hasattr (annotation , '__origin__' ):
132+ return annotation .__origin__ == Union
133+ return False
134+
135+
130136def using (attr ):
131137 def class_decorator (cls ):
132138 set_cls_attr (cls , PYCKSON_RULE_ATTR , attr )
Original file line number Diff line number Diff line change 1+ from typing import Union
12from unittest import TestCase
23
3- from pyckson .helpers import camel_case_name
4+ from pyckson .helpers import camel_case_name , is_union_annotation
45
56
67class CamelCaseNameTest (TestCase ):
@@ -9,3 +10,11 @@ def test_should_do_nothing_on_simple_names(self):
910
1011 def test_should_camel_case_when_there_is_an_underscore (self ):
1112 self .assertEqual (camel_case_name ('foo_bar' ), 'fooBar' )
13+
14+
15+ def test_should_detect_union_annotation ():
16+ annotation = Union [str , int ]
17+
18+ is_union = is_union_annotation (annotation )
19+
20+ assert is_union
You can’t perform that action at this time.
0 commit comments