Fix feature detection for positional-only arguments in lambdas (#2532)

This commit is contained in:
Zac Hatfield-Dodds 2021-10-12 15:45:58 +11:00 committed by GitHub
parent 3b2a7d196b
commit 2f3fa1f6d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 1 deletions

View File

@ -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_

View File

@ -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:

View File

@ -805,6 +805,10 @@ def test_get_features_used(self) -> None:
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")