From b4032a32320ab635d89c439287d60f03191db7df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20M=C3=A9ndez=20Bravo?= Date: Fri, 7 Aug 2020 11:11:57 -0700 Subject: [PATCH] Fix pyre error: kwonlydefaults is Optional --- libcst/codemod/_command.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/libcst/codemod/_command.py b/libcst/codemod/_command.py index 4529be00..1a11e91e 100644 --- a/libcst/codemod/_command.py +++ b/libcst/codemod/_command.py @@ -162,20 +162,16 @@ class MagicArgsCodemodCommand(CodemodCommand, ABC): ) # 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)