Skip to content

Commit

Permalink
Bug fix for Python 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
scnerd committed Apr 25, 2018
1 parent dc11e83 commit 6a155cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pragma/collapse_literals.py
@@ -1,6 +1,6 @@
import ast

from .core import TrackedContextTransformer, make_function_transformer, primitive_types
from .core import TrackedContextTransformer, make_function_transformer, primitive_ast_types
import logging
log = logging.getLogger(__name__)

Expand All @@ -9,7 +9,7 @@
class CollapseTransformer(TrackedContextTransformer):
def visit_Name(self, node):
res = self.resolve_literal(node)
if isinstance(res, (ast.Num, ast.Str, ast.JoinedStr, ast.Bytes, ast.NameConstant, ast.Constant)):
if isinstance(res, primitive_ast_types):
return res
return node

Expand Down
5 changes: 5 additions & 0 deletions pragma/core/resolve/__init__.py
Expand Up @@ -89,6 +89,11 @@ def resolve_name_or_attribute(node, ctxt):

primitive_types = tuple([str, bytes, bool, type(None)] + list(num_types) + list(float_types))

try:
primitive_ast_types = (ast.Num, ast.Str, ast.Bytes, ast.NameConstant, ast.Constant, ast.JoinedStr)
except AttributeError: # Python <3.6
primitive_ast_types = (ast.Num, ast.Str, ast.Bytes, ast.NameConstant, ast.Constant)


def make_binop(op):
def f(self, other):
Expand Down

0 comments on commit 6a155cb

Please sign in to comment.