Permalink
Browse files

Better repr() using qualified name

  • Loading branch information...
dahlia committed Nov 6, 2017
1 parent 46602a6 commit 8da591d615e779881631b290b57189a8fc19c4ac
Showing with 15 additions and 5 deletions.
  1. +5 −5 src/Nirum/Targets/Python.hs
  2. +10 −0 test/python/primitive_test.py
@@ -485,7 +485,6 @@ compileUnionTag source parentname d@(Tag typename' fields _) = do
[ ("nirum.validate", [("validate_union_type", "validate_union_type")])
, ("nirum.constructs", [("name_dict_type", "NameDict")])
]
typeRepr <- typeReprCompiler
arg <- parameterCompiler
ret <- returnCompiler
pyVer <- getPythonVersion
@@ -528,10 +527,11 @@ class $className($parentClass):
{ inits :: T.Text }
def __repr__(self){ ret "str" }:
return '\{0\}(\{1\})'.format(
{typeRepr "type(self)"},
', '.join('\{\}=\{\}'.format(attr, getattr(self, attr))
for attr in self.__slots__)
return (
$parentClass.__module__ + '.$parentClass.$className(' +
', '.join('\{0\}=\{1!r\}'.format(attr, getattr(self, attr))
for attr in self.__slots__) +
')'
)
def __eq__(self, other){ ret "bool" }:
@@ -203,6 +203,16 @@ def test_union():
last_name=u'wrong')
assert hash(WesternName(first_name=u'foo', middle_name=u'bar',
last_name=u'baz'))
if PY3:
assert repr(western_name) == (
"fixture.foo.MixedName.WesternName(first_name='foo', "
"middle_name='bar', last_name='baz')"
)
else:
assert repr(western_name) == (
"fixture.foo.MixedName.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)

0 comments on commit 8da591d

Please sign in to comment.