]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Imply 3.8+ when annotated assigments used with unparenthesized tuples (#2708)
authorBatuhan Taskaya <isidentical@gmail.com>
Fri, 17 Dec 2021 21:43:14 +0000 (00:43 +0300)
committerGitHub <noreply@github.com>
Fri, 17 Dec 2021 21:43:14 +0000 (13:43 -0800)
CHANGES.md
src/black/__init__.py
src/black/mode.py
tests/test_black.py

index ae0bf80da485ec7d53126c4c346610ab73704efd..0452f1820c4c139313b911ee205a05c53b6fa09c 100644 (file)
@@ -12,6 +12,8 @@
 - No longer color diff headers white as it's unreadable in light themed terminals
   (#2691)
 - Tuple unpacking on `return` and `yield` constructs now implies 3.8+ (#2700)
 - No longer color diff headers white as it's unreadable in light themed terminals
   (#2691)
 - Tuple unpacking on `return` and `yield` constructs now implies 3.8+ (#2700)
+- Unparenthesized tuples on annotated assignments (e.g
+  `values: Tuple[int, ...] = 1, 2, 3`) now implies 3.8+ (#2708)
 
 ## 21.12b0
 
 
 ## 21.12b0
 
index 08c239dc15561be1ceb41a7411957289880620ac..d8b98196aa068e9be8c192d71358333dab9377bf 100644 (file)
@@ -1218,6 +1218,13 @@ def get_features_used(  # noqa: C901
         ):
             features.add(Feature.UNPACKING_ON_FLOW)
 
         ):
             features.add(Feature.UNPACKING_ON_FLOW)
 
+        elif (
+            n.type == syms.annassign
+            and len(n.children) >= 4
+            and n.children[3].type == syms.testlist_star_expr
+        ):
+            features.add(Feature.ANN_ASSIGN_EXTENDED_RHS)
+
         # Python 2 only features (for its deprecation) except for integers, see above
         elif n.type == syms.print_stmt:
             features.add(Feature.PRINT_STMT)
         # Python 2 only features (for its deprecation) except for integers, see above
         elif n.type == syms.print_stmt:
             features.add(Feature.PRINT_STMT)
index b28dcd8d1494eee4c171b9a58a0f1faea29649e7..bd4428add66a22bb6f7db0bca6082a33f28df5bd 100644 (file)
@@ -50,6 +50,7 @@ class Feature(Enum):
     RELAXED_DECORATORS = 10
     PATTERN_MATCHING = 11
     UNPACKING_ON_FLOW = 12
     RELAXED_DECORATORS = 10
     PATTERN_MATCHING = 11
     UNPACKING_ON_FLOW = 12
+    ANN_ASSIGN_EXTENDED_RHS = 13
     FORCE_OPTIONAL_PARENTHESES = 50
 
     # __future__ flags
     FORCE_OPTIONAL_PARENTHESES = 50
 
     # __future__ flags
@@ -118,6 +119,7 @@ VERSION_TO_FEATURES: Dict[TargetVersion, Set[Feature]] = {
         Feature.ASSIGNMENT_EXPRESSIONS,
         Feature.POS_ONLY_ARGUMENTS,
         Feature.UNPACKING_ON_FLOW,
         Feature.ASSIGNMENT_EXPRESSIONS,
         Feature.POS_ONLY_ARGUMENTS,
         Feature.UNPACKING_ON_FLOW,
+        Feature.ANN_ASSIGN_EXTENDED_RHS,
     },
     TargetVersion.PY39: {
         Feature.UNICODE_LITERALS,
     },
     TargetVersion.PY39: {
         Feature.UNICODE_LITERALS,
@@ -131,6 +133,7 @@ VERSION_TO_FEATURES: Dict[TargetVersion, Set[Feature]] = {
         Feature.RELAXED_DECORATORS,
         Feature.POS_ONLY_ARGUMENTS,
         Feature.UNPACKING_ON_FLOW,
         Feature.RELAXED_DECORATORS,
         Feature.POS_ONLY_ARGUMENTS,
         Feature.UNPACKING_ON_FLOW,
+        Feature.ANN_ASSIGN_EXTENDED_RHS,
     },
     TargetVersion.PY310: {
         Feature.UNICODE_LITERALS,
     },
     TargetVersion.PY310: {
         Feature.UNICODE_LITERALS,
@@ -144,6 +147,7 @@ VERSION_TO_FEATURES: Dict[TargetVersion, Set[Feature]] = {
         Feature.RELAXED_DECORATORS,
         Feature.POS_ONLY_ARGUMENTS,
         Feature.UNPACKING_ON_FLOW,
         Feature.RELAXED_DECORATORS,
         Feature.POS_ONLY_ARGUMENTS,
         Feature.UNPACKING_ON_FLOW,
+        Feature.ANN_ASSIGN_EXTENDED_RHS,
         Feature.PATTERN_MATCHING,
     },
 }
         Feature.PATTERN_MATCHING,
     },
 }
index 8726cc10ddcf13a9c648f32225c32f0bc246fc63..628647ed9774d18a007e7d0d50538c98f6a715a8 100644 (file)
@@ -818,6 +818,18 @@ class BlackTestCase(BlackBaseTestCase):
         self.assertEqual(black.get_features_used(node), {Feature.UNPACKING_ON_FLOW})
         node = black.lib2to3_parse("def fn(): return a, *b, c")
         self.assertEqual(black.get_features_used(node), {Feature.UNPACKING_ON_FLOW})
         self.assertEqual(black.get_features_used(node), {Feature.UNPACKING_ON_FLOW})
         node = black.lib2to3_parse("def fn(): return a, *b, c")
         self.assertEqual(black.get_features_used(node), {Feature.UNPACKING_ON_FLOW})
+        node = black.lib2to3_parse("x = a, *b, c")
+        self.assertEqual(black.get_features_used(node), set())
+        node = black.lib2to3_parse("x: Any = regular")
+        self.assertEqual(black.get_features_used(node), set())
+        node = black.lib2to3_parse("x: Any = (regular, regular)")
+        self.assertEqual(black.get_features_used(node), set())
+        node = black.lib2to3_parse("x: Any = Complex(Type(1))[something]")
+        self.assertEqual(black.get_features_used(node), set())
+        node = black.lib2to3_parse("x: Tuple[int, ...] = a, b, c")
+        self.assertEqual(
+            black.get_features_used(node), {Feature.ANN_ASSIGN_EXTENDED_RHS}
+        )
 
     def test_get_features_used_for_future_flags(self) -> None:
         for src, features in [
 
     def test_get_features_used_for_future_flags(self) -> None:
         for src, features in [