Skip to content

Pass literals as kwargs #10237

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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
# Conflicts:
#	mypy/checkexpr.py
  • Loading branch information
97littleleaf11 committed Nov 26, 2021
commit 0d7a3734df4da3ff0d7930aacccd0214f72de406
48 changes: 17 additions & 31 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
from mypy.typeops import (
tuple_fallback, make_simplified_union, true_only, false_only, erase_to_union_or_bound,
function_type, callable_type, try_getting_str_literals, custom_special_method,
is_literal_type_like, try_getting_str_literals_from_type,
is_literal_type_like, try_expanding_sum_type_to_union, try_getting_str_literals_from_type
)
from mypy.message_registry import ErrorMessage
import mypy.errorcodes as codes
Expand Down Expand Up @@ -4027,38 +4027,24 @@ def is_valid_var_arg(self, typ: Type) -> bool:

def is_valid_keyword_var_arg(self, typ: Type) -> bool:
"""Is a type valid as a **kwargs argument?"""
mapping_type = self.chk.named_generic_type('typing.Mapping',
[self.named_type('builtins.str'),
AnyType(TypeOfAny.special_form)])
mapping_type = self.chk.named_generic_type(
'typing.Mapping', [self.named_type('builtins.str'), AnyType(TypeOfAny.special_form)])
typ = get_proper_type(typ)

if self.chk.options.python_version[0] >= 3:
return (
(is_subtype(typ, mapping_type))
or
(isinstance(typ, Instance) and
is_subtype(typ, self.chk.named_type('typing.Mapping')) and
(try_getting_str_literals_from_type(
map_instance_to_supertype(typ,
mapping_type.type).args[0]) is not None)))

else:
return (
(is_subtype(typ, self.chk.named_generic_type(
'typing.Mapping',
[self.named_type('builtins.str'),
AnyType(TypeOfAny.special_form)])))
or
(is_subtype(typ, self.chk.named_generic_type(
'typing.Mapping',
[self.named_type('builtins.unicode'),
AnyType(TypeOfAny.special_form)])))
or
(isinstance(typ, Instance) and
is_subtype(typ, self.chk.named_type('typing.Mapping')) and
try_getting_str_literals_from_type(
map_instance_to_supertype(typ,
mapping_type.type).args[0]) is not None))
ret = (
is_subtype(typ, mapping_type) or
(isinstance(typ, Instance) and
is_subtype(typ, self.chk.named_generic_type('typing.Mapping',
[UninhabitedType(), UninhabitedType()])) and
try_getting_str_literals_from_type(map_instance_to_supertype(
typ, mapping_type.type).arg[0]) is not None
) or
isinstance(typ, ParamSpecType)
)
if self.chk.options.python_version[0] < 3:
ret = ret or is_subtype(typ, self.chk.named_generic_type('typing.Mapping',
[self.named_type('builtins.unicode'), AnyType(TypeOfAny.special_form)]))
return ret

def has_member(self, typ: Type, member: str) -> bool:
"""Does type have member with the given name?"""
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.