Skip to content

Commit

Permalink
Merge pull request #363 from Kronuz/Kronuz-patch-pyre-2
Browse files Browse the repository at this point in the history
Fix pyre error: kwonlydefaults is Optional
  • Loading branch information
Kronuz authored Aug 7, 2020
2 parents 120123f + b4032a3 commit 27be9b1
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions libcst/codemod/_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,16 @@ def _instantiate(self, transform: Type[Codemod]) -> Codemod:
)
# No default, but we found something in scratch. So, forward it.
args.append(self.context.scratch[arg])
kwonlydefaults = argspec.kwonlydefaults or {}
for kwarg in argspec.kwonlyargs:
if (
kwarg not in self.context.scratch
and kwarg not in argspec.kwonlydefaults
):
if kwarg not in self.context.scratch and kwarg not in kwonlydefaults:
raise KeyError(
f"Visitor {transform.__name__} requires keyword arg {kwarg} but "
+ "it is not in our context nor does it have a default! It should "
+ "be provided by an argument returned from the 'add_args' method "
+ "or populated into context.scratch by a previous transform!"
)
kwargs[kwarg] = self.context.scratch.get(
kwarg, argspec.kwonlydefaults[kwarg]
)
kwargs[kwarg] = self.context.scratch.get(kwarg, kwonlydefaults[kwarg])

# Return an instance of the transform with those arguments
return transform(self.context, *args, **kwargs)
Expand Down

0 comments on commit 27be9b1

Please sign in to comment.