Fix feature detection for positional-only arguments in lambdas (#2532)
This commit is contained in:
parent
3b2a7d196b
commit
2f3fa1f6d0
@ -5,6 +5,7 @@
|
|||||||
### _Black_
|
### _Black_
|
||||||
|
|
||||||
- Add new `--workers` parameter (#2514)
|
- 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)
|
- Bumped typed-ast version minimum to 1.4.3 for 3.10 compatiblity (#2519)
|
||||||
|
|
||||||
### _Blackd_
|
### _Blackd_
|
||||||
|
@ -1123,7 +1123,11 @@ def get_features_used(node: Node) -> Set[Feature]:
|
|||||||
features.add(Feature.NUMERIC_UNDERSCORES)
|
features.add(Feature.NUMERIC_UNDERSCORES)
|
||||||
|
|
||||||
elif n.type == token.SLASH:
|
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)
|
features.add(Feature.POS_ONLY_ARGUMENTS)
|
||||||
|
|
||||||
elif n.type == token.COLONEQUAL:
|
elif n.type == token.COLONEQUAL:
|
||||||
|
@ -805,6 +805,10 @@ def test_get_features_used(self) -> None:
|
|||||||
self.assertEqual(black.get_features_used(node), set())
|
self.assertEqual(black.get_features_used(node), set())
|
||||||
node = black.lib2to3_parse(expected)
|
node = black.lib2to3_parse(expected)
|
||||||
self.assertEqual(black.get_features_used(node), set())
|
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:
|
def test_get_future_imports(self) -> None:
|
||||||
node = black.lib2to3_parse("\n")
|
node = black.lib2to3_parse("\n")
|
||||||
|
Loading…
Reference in New Issue
Block a user