Skip to content

Commit

Permalink
Qualify tag classes under union type classes
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Nov 6, 2017
1 parent 9a1fc0c commit 46602a6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Nirum/Targets/Python.hs
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,11 @@ class $className($parentClass):

def __hash__(self){ ret "int" }:
return hash($hashTuple)


$parentClass.$className = $className
if hasattr($parentClass, '__qualname__'):
$className.__qualname__ = $parentClass.__qualname__ + '.{className}'
|]
compilePrimitiveType :: PrimitiveTypeIdentifier -> CodeGen Code
compilePrimitiveType primitiveTypeIdentifier = do
Expand Down
3 changes: 3 additions & 0 deletions test/python/primitive_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def test_union():
assert MixedName.Tag.western_name.value == 'western_name'
assert MixedName.Tag.east_asian_name.value == 'east_asian_name'
assert MixedName.Tag.culture_agnostic_name.value == 'culture_agnostic_name'
assert WesternName is MixedName.WesternName # alias
assert isinstance(WesternName, type)
assert issubclass(WesternName, MixedName)
with raises(NotImplementedError):
Expand Down Expand Up @@ -202,6 +203,7 @@ def test_union():
last_name=u'wrong')
assert hash(WesternName(first_name=u'foo', middle_name=u'bar',
last_name=u'baz'))
assert EastAsianName is MixedName.EastAsianName
assert isinstance(EastAsianName, type)
assert issubclass(EastAsianName, MixedName)
east_asian_name = EastAsianName(family_name=u'foo', given_name=u'baz')
Expand All @@ -219,6 +221,7 @@ def test_union():
EastAsianName(family_name=1, given_name=u'baz')
with raises(TypeError):
EastAsianName(family_name=u'foo', given_name=2)
assert CultureAgnosticName is MixedName.CultureAgnosticName
assert isinstance(CultureAgnosticName, type)
assert issubclass(CultureAgnosticName, MixedName)
agnostic_name = CultureAgnosticName(fullname=u'foobar')
Expand Down

0 comments on commit 46602a6

Please sign in to comment.