Skip to content

Commit

Permalink
fixed up class testcase support for py3.6 due to ast differences in p…
Browse files Browse the repository at this point in the history
…y3.8/3.9
  • Loading branch information
nanobowers committed Oct 19, 2021
1 parent 5407d91 commit 4ed2398
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
12 changes: 9 additions & 3 deletions py2cr/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,15 @@ def visit_Constant(self, node):

@classmethod
def constant(cls, node, nilable=True):
#if not hasattr(node, "value"):
# return "_"
const_typename = node.value.__class__.__name__
if isinstance(node, ast.Constant): # py3.8+
const_typename = node.value.__class__.__name__
elif isinstance(node, ast.Num):
const_typename = node.n.__class__.__name__
elif isinstance(node, ast.Str):
const_typename = 'str'
else:
raise Exception("Invalid constant node: %s", node)

if const_typename in cls.name_map:
crystal_typename = cls.name_map[const_typename]
if nilable:
Expand Down
35 changes: 30 additions & 5 deletions tests/basic/class3.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
class A(object):
class II(object):
v = 1

a = A()
XX = A
x = XX()
print(x.v)
class SS(object):
v = "abcd"

class FF(object):
v = 1.234

ii = II()
XX = II
xx = XX()
print(ii.v)
print(xx.v)
print(XX.v)


ss = SS()
YY = SS
yy = YY()
print(ss.v)
print(yy.v)
print(YY.v)


ff = FF()
ZZ = FF
zz = ZZ()
print(ff.v)
print(zz.v)
print(ZZ.v)

0 comments on commit 4ed2398

Please sign in to comment.