Skip to content

Commit

Permalink
Detect pos-only args in lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Oct 12, 2021
1 parent 3b2a7d1 commit 93e8c45
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -5,6 +5,7 @@
### _Black_

- Add new `--workers` parameter (#2514)
- Fixed feature detection for positional-only arguments in lambdas
- Bumped typed-ast version minimum to 1.4.3 for 3.10 compatiblity (#2519)

### _Blackd_
Expand Down
6 changes: 5 additions & 1 deletion src/black/__init__.py
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_black.py
Expand Up @@ -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), set(Feature.POS_ONLY_ARGUMENTS))
node = black.lib2to3_parse("def fn(a, /, b): ...")
self.assertEqual(black.get_features_used(node), set(Feature.POS_ONLY_ARGUMENTS))

def test_get_future_imports(self) -> None:
node = black.lib2to3_parse("\n")
Expand Down

0 comments on commit 93e8c45

Please sign in to comment.