Skip to content

Commit

Permalink
Fix visiting string constants in CPython 3.8+
Browse files Browse the repository at this point in the history
The Cura builds target CPython 3.5.2 now so it's not a problem for that, but if we upgrade to CPython 3.8 or higher in the future, or right now for the package managers in Linux, this fixes some function evaluations.

Fixes #498.
  • Loading branch information
hroncok authored and Ghostkeeper committed Jul 10, 2019
1 parent 7ba6540 commit d7ed5eb
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion UM/Settings/SettingFunction.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018 Ultimaker B.V.
# Copyright (c) 2019 Ultimaker B.V.
# Uranium is released under the terms of the LGPLv3 or higher.

import ast
Expand Down Expand Up @@ -180,10 +180,18 @@ def visit_Name(self, node: ast.Name) -> None: # [CodeStyle: ast.NodeVisitor req
self.values.add(node.id)
self.keys.add(node.id)

## This one is used before Python 3.8 to visit string types.
#
# visit_Str will be marked as deprecated from Python 3.8 and onwards.
def visit_Str(self, node: ast.AST) -> None:
if node.s not in self._knownNames and node.s not in dir(builtins): # type: ignore #AST uses getattr stuff, so ignore type of node.s.
self.keys.add(node.s) # type: ignore

## This one is used on Python 3.8+ to visit string types.
def visit_Constant(self, node: ast.AST) -> None:
if isinstance(node.value, str) and node.value not in self._knownNames and node.value not in dir(builtins): # type: ignore #AST uses getattr stuff, so ignore type of node.value.
self.keys.add(node.value) # type: ignore

_knownNames = {
"math",
"max",
Expand Down

0 comments on commit d7ed5eb

Please sign in to comment.