From 2f3fa1f6d0cbc2a3f31c7440c422da173b068e7b Mon Sep 17 00:00:00 2001 From: Zac Hatfield-Dodds Date: Tue, 12 Oct 2021 15:45:58 +1100 Subject: [PATCH] Fix feature detection for positional-only arguments in lambdas (#2532) --- CHANGES.md | 1 + src/black/__init__.py | 6 +++++- tests/test_black.py | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index f5b11de..864f0a5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ ### _Black_ - Add new `--workers` parameter (#2514) +- Fixed feature detection for positional-only arguments in lambdas (#2532) - Bumped typed-ast version minimum to 1.4.3 for 3.10 compatiblity (#2519) ### _Blackd_ diff --git a/src/black/__init__.py b/src/black/__init__.py index 83a3923..fdbaf04 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -1123,7 +1123,11 @@ def get_features_used(node: Node) -> Set[Feature]: features.add(Feature.NUMERIC_UNDERSCORES) elif n.type == token.SLASH: - if n.parent and n.parent.type in {syms.typedargslist, syms.arglist}: + if n.parent and n.parent.type in { + syms.typedargslist, + syms.arglist, + syms.varargslist, + }: features.add(Feature.POS_ONLY_ARGUMENTS) elif n.type == token.COLONEQUAL: diff --git a/tests/test_black.py b/tests/test_black.py index f25db1b..beb56cf 100644 --- a/tests/test_black.py +++ b/tests/test_black.py @@ -805,6 +805,10 @@ class BlackTestCase(BlackBaseTestCase): self.assertEqual(black.get_features_used(node), set()) node = black.lib2to3_parse(expected) self.assertEqual(black.get_features_used(node), set()) + node = black.lib2to3_parse("lambda a, /, b: ...") + self.assertEqual(black.get_features_used(node), {Feature.POS_ONLY_ARGUMENTS}) + node = black.lib2to3_parse("def fn(a, /, b): ...") + self.assertEqual(black.get_features_used(node), {Feature.POS_ONLY_ARGUMENTS}) def test_get_future_imports(self) -> None: node = black.lib2to3_parse("\n") -- 2.39.5