Skip to content

Commit 07ed7af

Browse files
authored
Merge pull request #1569 from google/google_sync
Google sync
2 parents c6869a1 + 69a48e4 commit 07ed7af

6 files changed

Lines changed: 41 additions & 5 deletions

File tree

pytype/abstract/_function_base.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,17 +525,16 @@ def _map_args(self, node, args):
525525
raise function.WrongKeywordArgs(sig, args, self.ctx, posonly_kws)
526526
callargs.update(positional)
527527
callargs.update(kws)
528-
for key, kwonly in self.get_nondefault_params():
528+
for key, kwonly in itertools.chain(
529+
self.get_nondefault_params(),
530+
((key, True) for key in sig.kwonly_params)):
529531
if key not in callargs:
530532
if args.starstarargs or (args.starargs and not kwonly):
531533
# We assume that because we have *args or **kwargs, we can use these
532534
# to fill in any parameters we might be missing.
533535
callargs[key] = self.ctx.new_unsolvable(node)
534536
else:
535537
raise function.MissingParameter(sig, args, self.ctx, key)
536-
for key in sig.kwonly_params:
537-
if key not in callargs:
538-
raise function.MissingParameter(sig, args, self.ctx, key)
539538
if sig.varargs_name:
540539
varargs_name = sig.varargs_name
541540
extraneous = posargs[self.argcount(node):]

pytype/blocks/blocks.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ def __init__(self, code, bytecode, order):
161161
for insn in bytecode:
162162
insn.code = self
163163

164+
def __repr__(self):
165+
return f"OrderedCode({self.qualname}, version={self.python_version})"
166+
164167
@property
165168
def co_consts(self):
166169
# The blocks/pyc code mixes CodeType and OrderedCode objects when

pytype/matcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ def _match_type_param_against_type_param(self, t1, t2, subst, view):
474474
# constraints even if t1 is bounded.
475475
if not t1.constraints:
476476
return None # t1 is unconstrained, t2 has constraints
477-
if set(t1.constraints) - set(t2.constraints):
477+
if any(c not in t2.constraints for c in t1.constraints):
478478
return None # t1 is more permissive than t2
479479
elif t2.bound:
480480
if t1.bound:

pytype/overlays/special_builtins.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,11 @@ def call(self, node, func, args, alias_map=None):
781781
else:
782782
return super().call(node, func, args, alias_map)
783783

784+
def get_special_attribute(self, node, name, valself):
785+
# For doing something like getting the __getitem__ attribute to subscript
786+
# dict, we want to use the real dict type.
787+
return self.ctx.convert.dict_type.get_special_attribute(node, name, valself)
788+
784789

785790
class Type(BuiltinClass, mixin.HasSlots):
786791

pytype/tests/test_dataclasses.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,18 @@ class C:
781781
def __init__(self, *, x: int = ..., y: str) -> None: ...
782782
""")
783783

784+
@test_utils.skipBeforePy((3, 10), "KW_ONLY is new in 3.10")
785+
def test_kwonly_and_kwargs(self):
786+
self.Check("""
787+
import dataclasses
788+
@dataclasses.dataclass
789+
class C:
790+
_: dataclasses.KW_ONLY
791+
x: int
792+
def f(**kwargs):
793+
return C(**kwargs)
794+
""")
795+
784796
def test_star_import(self):
785797
with self.DepTree([("foo.pyi", """
786798
import dataclasses

pytype/tests/test_typevar2.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,23 @@ def f(x: T) -> T:
10571057
f("oops") # wrong-arg-types
10581058
""")
10591059

1060+
@test_utils.skipBeforePy((3, 9), "subscripting builtins.dict is new in 3.9")
1061+
def test_builtin_dict_constraint(self):
1062+
with self.DepTree([("foo.pyi", """
1063+
from typing import TypeVar
1064+
T = TypeVar('T', int, dict[str, int])
1065+
class C:
1066+
def f(self, x: T) -> T: ...
1067+
""")]):
1068+
self.Check("""
1069+
import foo
1070+
from typing import TypeVar
1071+
T = TypeVar('T', int, dict[str, int])
1072+
class C(foo.C):
1073+
def f(self, x: T) -> T:
1074+
return x
1075+
""")
1076+
10601077

10611078
if __name__ == "__main__":
10621079
test_base.main()

0 commit comments

Comments
 (0)