Skip to content

Commit

Permalink
Merge pull request #624 from google/google_sync
Browse files Browse the repository at this point in the history
Google sync
  • Loading branch information
rchen152 authored Jul 20, 2020
2 parents 1264ba3 + 6b463ad commit c0f4fd2
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Version 2020.07.20
* pyi parser: support importing TypedDict from typing_extensions.

Version 2020.07.14
* Populate the `cls` arg in classmethods with the class type.
* Log [not-supported-yet] as soon as a recursive type alias is defined.
Expand Down
2 changes: 1 addition & 1 deletion pytype/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# pylint: skip-file
__version__ = '2020.07.14'
__version__ = '2020.07.20'
6 changes: 5 additions & 1 deletion pytype/pyi/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
# Typing members that represent sets of types.
_TYPING_SETS = ("typing.Intersection", "typing.Optional", "typing.Union")

_TYPED_DICT_ALIASES = (
"typing.TypedDict",
parser_constants.EXTERNAL_NAME_PREFIX + "typing_extensions.TypedDict")


_Params = collections.namedtuple("_", ["required",
"starargs", "starstarargs",
Expand Down Expand Up @@ -1113,7 +1117,7 @@ def new_class(self, decorators, class_name, parent_args, defs):
raise ParseError("Unexpected classdef kwarg %r" % keyword)
elif keyword == "total" and not any(
isinstance(parent, pytd.NamedType) and
parent.name == "typing.TypedDict" for parent in parents):
parent.name in _TYPED_DICT_ALIASES for parent in parents):
raise ParseError(
"'total' allowed as classdef kwarg only for TypedDict subclasses")
if keyword == "metaclass":
Expand Down
13 changes: 13 additions & 0 deletions pytype/pyi/parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,19 @@ class Foo(TypedDict): ...
class Foo(object, total=False): ...
""", 1, "'total' allowed as classdef kwarg only for TypedDict subclasses")

def test_typing_extensions_typed_dict(self):
self.check("""
from typing_extensions import TypedDict
class Foo(TypedDict, total=False): ...
""", """
import typing_extensions
from typing_extensions import TypedDict
class Foo(typing_extensions.TypedDict): ...
""")

def test_multiple_classdef_kwargs(self):
self.check("""
from typing import TypedDict
Expand Down
1 change: 0 additions & 1 deletion pytype/pytd/builtins/2/__builtin__.pytd
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ class dict(Dict[_K, _V]):
self = dict[_K or str, _V or _V2]
def update(self, E, ...) -> None:
self = dict[?, ?]
def update(self) -> NoneType
def viewitems(self) -> dict_items[_K,_V]
def viewkeys(self) -> dict_keys[_K]
def viewvalues(self) -> dict_values[_V]
Expand Down
2 changes: 1 addition & 1 deletion pytype/pytd/builtins/3/__builtin__.pytd
Original file line number Diff line number Diff line change
Expand Up @@ -1175,4 +1175,4 @@ def open(
errors: Optional[str] = ...,
newline: Optional[str] = ...,
closefd: bool = ...,
) -> IO: ...
) -> IO: ...
2 changes: 1 addition & 1 deletion pytype/pytd/builtins/3/builtins.pytd
Original file line number Diff line number Diff line change
Expand Up @@ -1175,4 +1175,4 @@ def open(
errors: Optional[str] = ...,
newline: Optional[str] = ...,
closefd: bool = ...,
) -> IO: ...
) -> IO: ...
1 change: 1 addition & 0 deletions pytype/tools/traces/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A flexible, lightweight library to access the type information in pytype’s opcode traces.

0 comments on commit c0f4fd2

Please sign in to comment.