| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
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
Sorry, something went wrong.
|
@AlexWaygood indeed! This is a better way! 👍 |
Sorry, something went wrong.
|
except, it is a bit more complex. There might be two conditions at once:
|
Sorry, something went wrong.
Ah shoot, yes, it's not a 1:1 rewrite, is it. The original doesn't use else:. Let's go with your way for now then :) |
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks!
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Context: python/mypy#16939 (comment)
New mypy version detected this typing problem: dict[str, TypeSet | bool] is not the correct type for **kwargs of str_converter.__init__:
(the error message looks cryptic).
str_converter.__init__ has this type:
So, basically you can only say that **kwargs can be dict[str, Any].
This is why I removed this alias.