Rename to needs_parentheses

This commit is contained in:
Alex Hall 2019-05-03 21:50:33 +02:00 committed by Ram Rachum
parent 7a1b457013
commit 750ef4c639
2 changed files with 18 additions and 18 deletions

View File

@ -7,7 +7,7 @@ from . import utils
from . import pycompat
def needs_parens(source):
def needs_parentheses(source):
def code(s):
return compile(s, '<variable>', 'eval').co_code
@ -19,7 +19,7 @@ class BaseVariable(pycompat.ABC):
self.source = source
self.exclude = utils.ensure_tuple(exclude)
self.code = compile(source, '<variable>', 'eval')
if needs_parens(source):
if needs_parentheses(source):
self.unambiguous_source = '({})'.format(source)
else:
self.unambiguous_source = source

View File

@ -9,7 +9,7 @@ from python_toolbox import sys_tools, temp_file_tools
import pytest
import pysnooper
from pysnooper.variables import needs_parens
from pysnooper.variables import needs_parentheses
from .utils import (assert_output, VariableEntry, CallEntry, LineEntry,
ReturnEntry, OpcodeEntry, ReturnValueEntry, ExceptionEntry)
@ -617,18 +617,18 @@ def test_error_in_overwrite_argument():
return y + x
def test_needs_parens():
assert not needs_parens('x')
assert not needs_parens('x.y')
assert not needs_parens('x.y.z')
assert not needs_parens('x.y.z[0]')
assert not needs_parens('x.y.z[0]()')
assert not needs_parens('x.y.z[0]()(3, 4 * 5)')
assert not needs_parens('foo(x)')
assert not needs_parens('foo(x+y)')
assert not needs_parens('(x+y)')
assert not needs_parens('[x+1 for x in ()]')
assert needs_parens('x + y')
assert needs_parens('x * y')
assert needs_parens('x and y')
assert needs_parens('x if z else y')
def test_needs_parentheses():
assert not needs_parentheses('x')
assert not needs_parentheses('x.y')
assert not needs_parentheses('x.y.z')
assert not needs_parentheses('x.y.z[0]')
assert not needs_parentheses('x.y.z[0]()')
assert not needs_parentheses('x.y.z[0]()(3, 4 * 5)')
assert not needs_parentheses('foo(x)')
assert not needs_parentheses('foo(x+y)')
assert not needs_parentheses('(x+y)')
assert not needs_parentheses('[x+1 for x in ()]')
assert needs_parentheses('x + y')
assert needs_parentheses('x * y')
assert needs_parentheses('x and y')
assert needs_parentheses('x if z else y')