From 750ef4c639ebd0109f61012f531fa9cd1b5c8c8f Mon Sep 17 00:00:00 2001 From: Alex Hall Date: Fri, 3 May 2019 21:50:33 +0200 Subject: [PATCH] Rename to needs_parentheses --- pysnooper/variables.py | 4 ++-- tests/test_pysnooper.py | 32 ++++++++++++++++---------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/pysnooper/variables.py b/pysnooper/variables.py index d2ed137..f3db008 100644 --- a/pysnooper/variables.py +++ b/pysnooper/variables.py @@ -7,7 +7,7 @@ from . import utils from . import pycompat -def needs_parens(source): +def needs_parentheses(source): def code(s): return compile(s, '', 'eval').co_code @@ -19,7 +19,7 @@ class BaseVariable(pycompat.ABC): self.source = source self.exclude = utils.ensure_tuple(exclude) self.code = compile(source, '', 'eval') - if needs_parens(source): + if needs_parentheses(source): self.unambiguous_source = '({})'.format(source) else: self.unambiguous_source = source diff --git a/tests/test_pysnooper.py b/tests/test_pysnooper.py index aba3c7a..c9586b8 100644 --- a/tests/test_pysnooper.py +++ b/tests/test_pysnooper.py @@ -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')