Hello community,

here is the log from the commit of package python-pyupgrade for 
openSUSE:Factory checked in at 2020-12-09 22:12:52
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-pyupgrade (Old)
 and      /work/SRC/openSUSE:Factory/.python-pyupgrade.new.2328 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "python-pyupgrade"

Wed Dec  9 22:12:52 2020 rev:4 rq:853810 version:2.7.4

Changes:
--------
--- /work/SRC/openSUSE:Factory/python-pyupgrade/python-pyupgrade.changes        
2020-11-09 13:59:00.875754318 +0100
+++ 
/work/SRC/openSUSE:Factory/.python-pyupgrade.new.2328/python-pyupgrade.changes  
    2020-12-09 22:12:52.963155924 +0100
@@ -1,0 +2,6 @@
+Wed Nov 25 20:49:51 UTC 2020 - Sebastian Wagner <sebix+novell....@sebix.at>
+
+- Update to version 2.7.4:
+ - parenthesize expressions when replacing six calls when needed
+
+-------------------------------------------------------------------

Old:
----
  python-pyupgrade-2.7.3.tar.gz

New:
----
  python-pyupgrade-2.7.4.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ python-pyupgrade.spec ++++++
--- /var/tmp/diff_new_pack.AosHZB/_old  2020-12-09 22:12:53.443156411 +0100
+++ /var/tmp/diff_new_pack.AosHZB/_new  2020-12-09 22:12:53.447156414 +0100
@@ -18,7 +18,7 @@
 
 %{?!python_module:%define python_module() python-%{**} python3-%{**}}
 Name:           python-pyupgrade
-Version:        2.7.3
+Version:        2.7.4
 Release:        0
 Summary:        A tool to automatically upgrade syntax for newer versions
 License:        MIT

++++++ python-pyupgrade-2.7.3.tar.gz -> python-pyupgrade-2.7.4.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pyupgrade-2.7.3/.pre-commit-config.yaml 
new/pyupgrade-2.7.4/.pre-commit-config.yaml
--- old/pyupgrade-2.7.3/.pre-commit-config.yaml 2020-10-22 20:26:32.000000000 
+0200
+++ new/pyupgrade-2.7.4/.pre-commit-config.yaml 2020-11-11 01:06:38.000000000 
+0100
@@ -34,7 +34,7 @@
     -   id: add-trailing-comma
         args: [--py36-plus]
 -   repo: https://github.com/asottile/pyupgrade
-    rev: v2.7.3
+    rev: v2.7.4
     hooks:
     -   id: pyupgrade
         args: [--py36-plus]
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pyupgrade-2.7.3/README.md 
new/pyupgrade-2.7.4/README.md
--- old/pyupgrade-2.7.3/README.md       2020-10-22 20:26:32.000000000 +0200
+++ new/pyupgrade-2.7.4/README.md       2020-11-11 01:06:38.000000000 +0100
@@ -1,5 +1,6 @@
 [![Build 
Status](https://dev.azure.com/asottile/asottile/_apis/build/status/asottile.pyupgrade?branchName=master)](https://dev.azure.com/asottile/asottile/_build/latest?definitionId=2&branchName=master)
 [![Azure DevOps 
coverage](https://img.shields.io/azure-devops/coverage/asottile/asottile/2/master.svg)](https://dev.azure.com/asottile/asottile/_build/latest?definitionId=2&branchName=master)
+[![pre-commit.ci 
status](https://results.pre-commit.ci/badge/github/asottile/pyupgrade/master.svg)](https://results.pre-commit.ci/latest/github/asottile/pyupgrade/master)
 
 pyupgrade
 =========
@@ -19,7 +20,7 @@
 
 ```yaml
 -   repo: https://github.com/asottile/pyupgrade
-    rev: v2.7.3
+    rev: v2.7.4
     hooks:
     -   id: pyupgrade
 ```
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pyupgrade-2.7.3/azure-pipelines.yml 
new/pyupgrade-2.7.4/azure-pipelines.yml
--- old/pyupgrade-2.7.3/azure-pipelines.yml     2020-10-22 20:26:32.000000000 
+0200
+++ new/pyupgrade-2.7.4/azure-pipelines.yml     2020-11-11 01:06:38.000000000 
+0100
@@ -13,7 +13,6 @@
       ref: refs/tags/v2.0.0
 
 jobs:
-- template: job--pre-commit.yml@asottile
 - template: job--python-tox.yml@asottile
   parameters:
     toxenvs: [py37]
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pyupgrade-2.7.3/pyupgrade.py 
new/pyupgrade-2.7.4/pyupgrade.py
--- old/pyupgrade-2.7.3/pyupgrade.py    2020-10-22 20:26:32.000000000 +0200
+++ new/pyupgrade-2.7.4/pyupgrade.py    2020-11-11 01:06:38.000000000 +0100
@@ -57,6 +57,13 @@
 
 _KEYWORDS = frozenset(keyword.kwlist)
 
+_EXPR_NEEDS_PARENS: Tuple[Type[ast.expr], ...] = (
+    ast.Await, ast.BinOp, ast.BoolOp, ast.Compare, ast.GeneratorExp, ast.IfExp,
+    ast.Lambda, ast.UnaryOp,
+)
+if sys.version_info >= (3, 8):  # pragma: no cover (py38+)
+    _EXPR_NEEDS_PARENS += (ast.NamedExpr,)
+
 
 def parse_format(s: str) -> Tuple[DotFormatPart, ...]:
     """Makes the empty string not a special case.  In the stdlib, there's
@@ -1103,7 +1110,6 @@
     'u': '{args[0]}',
     'byte2int': '{args[0]}[0]',
     'indexbytes': '{args[0]}[{rest}]',
-    'int2byte': 'bytes(({args[0]},))',
     'iteritems': '{args[0]}.items()',
     'iterkeys': '{args[0]}.keys()',
     'itervalues': '{args[0]}.values()',
@@ -1122,6 +1128,7 @@
     'assertRaisesRegex': '{args[0]}.assertRaisesRegex({rest})',
     'assertRegex': '{args[0]}.assertRegex({rest})',
 }
+SIX_INT2BYTE_TMPL = 'bytes(({args[0]},))'
 SIX_B_TMPL = 'b{args[0]}'
 WITH_METACLASS_NO_BASES_TMPL = 'metaclass={args[0]}'
 WITH_METACLASS_BASES_TMPL = '{rest}, metaclass={args[0]}'
@@ -1244,6 +1251,7 @@
         self.six_add_metaclass: Set[Offset] = set()
         self.six_b: Set[Offset] = set()
         self.six_calls: Dict[Offset, ast.Call] = {}
+        self.six_calls_int2byte: Set[Offset] = set()
         self.six_iter: Dict[Offset, ast.Call] = {}
         self._previous_node: Optional[ast.AST] = None
         self.six_raise_from: Set[Offset] = set()
@@ -1534,9 +1542,19 @@
             self.six_type_ctx[_ast_to_offset(node.args[1])] = arg
         elif self._is_six(node.func, ('b', 'ensure_binary')):
             self.six_b.add(_ast_to_offset(node))
-        elif self._is_six(node.func, SIX_CALLS) and not _starargs(node):
+        elif (
+                self._is_six(node.func, SIX_CALLS) and
+                node.args and
+                not _starargs(node)
+        ):
             self.six_calls[_ast_to_offset(node)] = node
         elif (
+                self._is_six(node.func, ('int2byte',)) and
+                node.args and
+                not _starargs(node)
+        ):
+            self.six_calls_int2byte.add(_ast_to_offset(node))
+        elif (
                 isinstance(node.func, ast.Name) and
                 node.func.id == 'next' and
                 not _starargs(node) and
@@ -2006,8 +2024,12 @@
         end: int,
         args: List[Tuple[int, int]],
         tmpl: str,
+        *,
+        parens: Sequence[int] = (),
 ) -> None:
     arg_strs = [_arg_str(tokens, *arg) for arg in args]
+    for paren in parens:
+        arg_strs[paren] = f'({arg_strs[paren]})'
 
     start_rest = args[0][1] + 1
     while (
@@ -2062,6 +2084,7 @@
             visitor.six_add_metaclass,
             visitor.six_b,
             visitor.six_calls,
+            visitor.six_calls_int2byte,
             visitor.six_iter,
             visitor.six_raise_from,
             visitor.six_reraise,
@@ -2167,7 +2190,14 @@
             call = visitor.six_calls[token.offset]
             assert isinstance(call.func, (ast.Name, ast.Attribute))
             template = _get_tmpl(SIX_CALLS, call.func)
-            _replace_call(tokens, i, end, func_args, template)
+            if isinstance(call.args[0], _EXPR_NEEDS_PARENS):
+                _replace_call(tokens, i, end, func_args, template, parens=(0,))
+            else:
+                _replace_call(tokens, i, end, func_args, template)
+        elif token.offset in visitor.six_calls_int2byte:
+            j = _find_open_paren(tokens, i)
+            func_args, end = _parse_call_args(tokens, j)
+            _replace_call(tokens, i, end, func_args, SIX_INT2BYTE_TMPL)
         elif token.offset in visitor.six_raise_from:
             j = _find_open_paren(tokens, i)
             func_args, end = _parse_call_args(tokens, j)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pyupgrade-2.7.3/setup.cfg 
new/pyupgrade-2.7.4/setup.cfg
--- old/pyupgrade-2.7.3/setup.cfg       2020-10-22 20:26:32.000000000 +0200
+++ new/pyupgrade-2.7.4/setup.cfg       2020-11-11 01:06:38.000000000 +0100
@@ -1,6 +1,6 @@
 [metadata]
 name = pyupgrade
-version = 2.7.3
+version = 2.7.4
 description = A tool to automatically upgrade syntax for newer versions.
 long_description = file: README.md
 long_description_content_type = text/markdown
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pyupgrade-2.7.3/tests/six_test.py 
new/pyupgrade-2.7.4/tests/six_test.py
--- old/pyupgrade-2.7.3/tests/six_test.py       2020-10-22 20:26:32.000000000 
+0200
+++ new/pyupgrade-2.7.4/tests/six_test.py       2020-11-11 01:06:38.000000000 
+0100
@@ -1,3 +1,5 @@
+import sys
+
 import pytest
 
 from pyupgrade import _fix_py3_plus
@@ -42,6 +44,7 @@
             id='relative import might not be six',
         ),
         ('traceback.format_exc(*sys.exc_info())'),
+        pytest.param('six.iteritems()', id='wrong argument count'),
     ),
 )
 def test_fix_six_noop(s):
@@ -382,12 +385,76 @@
             'print(next(iter({1:2}.values())))\n',
             id='six.itervalues inside next(...)',
         ),
+        pytest.param(
+            'for _ in six.itervalues({} or y): pass',
+            'for _ in ({} or y).values(): pass',
+            id='needs parenthesizing for BoolOp',
+        ),
+        pytest.param(
+            'for _ in six.itervalues({} | y): pass',
+            'for _ in ({} | y).values(): pass',
+            id='needs parenthesizing for BinOp',
+        ),
+        pytest.param(
+            'six.int2byte(x | y)',
+            'bytes((x | y,))',
+            id='no parenthesize for int2byte BinOP',
+        ),
+        pytest.param(
+            'six.iteritems(+weird_dct)',
+            '(+weird_dct).items()',
+            id='needs parenthesizing for UnaryOp',
+        ),
+        pytest.param(
+            'x = six.get_method_function(lambda: x)',
+            'x = (lambda: x).__func__',
+            id='needs parenthesizing for Lambda',
+        ),
+        pytest.param(
+            'for _ in six.itervalues(x if 1 else y): pass',
+            'for _ in (x if 1 else y).values(): pass',
+            id='needs parenthesizing for IfExp',
+        ),
+        # this one is bogus / impossible, but parenthesize it anyway
+        pytest.param(
+            'six.itervalues(x for x in y)',
+            '(x for x in y).values()',
+            id='needs parentehsizing for GeneratorExp',
+        ),
+        pytest.param(
+            'async def f():\n'
+            '    return six.iteritems(await y)\n',
+            'async def f():\n'
+            '    return (await y).items()\n',
+            id='needs parenthesizing for Await',
+        ),
+        # this one is bogus / impossible, but parenthesize it anyway
+        pytest.param(
+            'six.itervalues(x < y)',
+            '(x < y).values()',
+            id='needs parentehsizing for Compare',
+        ),
     ),
 )
 def test_fix_six(s, expected):
     assert _fix_py3_plus(s, (3,)) == expected
 
 
+@pytest.mark.xfail(sys.version_info < (3, 8), reason='walrus')
+@pytest.mark.parametrize(
+    ('s', 'expected'),
+    (
+        pytest.param(
+            'for _ in six.itervalues(x := y): pass',
+            'for _ in (x := y).values(): pass',
+            id='needs parenthesizing for NamedExpr',
+        ),
+    ),
+)
+def test_fix_six_py38_plus(s, expected):
+    assert _fix_py3_plus(s, (3,)) == expected
+
+
 @pytest.mark.parametrize(
     ('s', 'expected'),
     (
_______________________________________________
openSUSE Commits mailing list -- commit@lists.opensuse.org
To unsubscribe, email commit-le...@lists.opensuse.org
List Netiquette: https://en.opensuse.org/openSUSE:Mailing_list_netiquette
List Archives: 
https://lists.opensuse.org/archives/list/commit@lists.opensuse.org

Reply via email to