-
-
Notifications
You must be signed in to change notification settings - Fork 30.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove ConverterKeywordDict
alias in clinic.py
#115843
Conversation
5d8959f
to
a59ca06
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or perhaps we could do something like this? It would be slightly less dynamic, meaning mypy would have a higher chance of understanding what we're doing here:
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -4069,8 +4069,6 @@ def parse_arg(self, argname: str, displayname: str, *, limited_capi: bool) -> st
# mapping from arguments to format unit *and* registers the
# legacy C converter for that format unit.
#
-ConverterKeywordDict = dict[str, TypeSet | bool]
-
def r(format_unit: str,
*,
accept: TypeSet,
@@ -4086,12 +4084,10 @@ def r(format_unit: str,
#
# also don't add the converter for 's' because
# the metaclass for CConverter adds it for us.
- kwargs: ConverterKeywordDict = {}
if accept != {str}:
- kwargs['accept'] = accept
- if zeroes:
- kwargs['zeroes'] = True
- added_f = functools.partial(str_converter, **kwargs)
+ added_f = functools.partial(str_converter, accept=accept)
+ else:
+ added_f = functools.partial(str_converter, zeroes=True)
legacy_converters[format_unit] = added_f
d = str_converter_argument_map
@AlexWaygood indeed! This is a better way! 👍 |
except, it is a bit more complex. There might be two conditions at once:
|
Ah shoot, yes, it's not a 1:1 rewrite, is it. The original doesn't use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Context: python/mypy#16939 (comment)
New mypy version detected this typing problem:
dict[str, TypeSet | bool]
is not the correct type for**kwargs
ofstr_converter.__init__
:(the error message looks cryptic).
str_converter.__init__
has this type:So, basically you can only say that
**kwargs
can bedict[str, Any]
.This is why I removed this alias.