Remove ConverterKeywordDict alias in clinic.py#115843
Merged
AlexWaygood merged 1 commit intopython:mainfrom Feb 23, 2024
Merged
Remove ConverterKeywordDict alias in clinic.py#115843AlexWaygood merged 1 commit intopython:mainfrom
ConverterKeywordDict alias in clinic.py#115843AlexWaygood merged 1 commit intopython:mainfrom
Conversation
5d8959f to
a59ca06
Compare
hauntsaninja
approved these changes
Feb 23, 2024
AlexWaygood
reviewed
Feb 23, 2024
Member
AlexWaygood
left a comment
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
Member
Author
|
@AlexWaygood indeed! This is a better way! 👍 |
Member
Author
|
except, it is a bit more complex. There might be two conditions at once:
|
Member
Ah shoot, yes, it's not a 1:1 rewrite, is it. The original doesn't use |
woodruffw
pushed a commit
to woodruffw-forks/cpython
that referenced
this pull request
Mar 4, 2024
diegorusso
pushed a commit
to diegorusso/cpython
that referenced
this pull request
Apr 17, 2024
LukasWoodtli
pushed a commit
to LukasWoodtli/cpython
that referenced
this pull request
Jan 22, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context: python/mypy#16939 (comment)
New mypy version detected this typing problem:
dict[str, TypeSet | bool]is not the correct type for**kwargsofstr_converter.__init__:(the error message looks cryptic).
str_converter.__init__has this type:So, basically you can only say that
**kwargscan bedict[str, Any].This is why I removed this alias.