Skip to content

Commit 8af6303

Browse files
authored
Merge pull request #1585 from google/google_sync
Google sync
2 parents f9c7c6c + ff392ba commit 8af6303

5 files changed

Lines changed: 32 additions & 3 deletions

File tree

CHANGELOG

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Version 2024.02.13:
2+
3+
Bug fixes:
4+
* Fix: pytype.single -> pytype.main.
5+
* Catch UnicodeDecodeError when attempting to read excluded files.
6+
* Add protocol overload to definition of builtins.divmod.
7+
18
Version 2024.02.09:
29

310
Updates:

pytype/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# pylint: skip-file
2-
__version__ = '2024.02.09'
2+
__version__ = '2024.02.13'

pytype/file_utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ def is_file_script(filename, directory=None):
148148
# of course we assume that they start with a shebang
149149
file_path = expand_path(filename, directory)
150150
if path_utils.isfile(file_path):
151-
with open(file_path, "r") as file:
152-
line = file.readline().rstrip().lower()
151+
with open(file_path, "r") as fi:
152+
try:
153+
line = fi.readline().rstrip().lower()
154+
except UnicodeDecodeError:
155+
return False
153156
return re.fullmatch(r"#!.+python3?", line) is not None

pytype/stubs/builtins/builtins.pytd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,19 @@ def coerce(x: _T, y: _T) -> tuple[_T, _T]: ... # E.g. coerce([], [1]) -> ([], [
6565
def compile(source, filename: str, mode: str, flags: int = ..., dont_inherit: int = ..., optimize: int = ...) -> code: ...
6666
def delattr(object, name: Union[str, bytes, bytearray]) -> None: ...
6767
def dir(*args, **kwargs) -> list[str]: ...
68+
69+
class _SupportsDivMod(Protocol[_T, _T2, _T3]):
70+
def __divmod__(self, other: _T) -> tuple[_T2, _T3]: ...
71+
72+
@overload
6873
def divmod(x: int, y: int) -> tuple[int, int]: ...
74+
@overload
6975
def divmod(x: Union[int, float], y: Union[int, float]) -> tuple[float, float]: ...
76+
@overload
7077
def divmod(x: Union[int, float, complex], y: Union[int, float, complex]) -> tuple[complex, complex]: ...
78+
@overload
79+
def divmod(x: _SupportsDivMod[_T, _T2, _T3], y: _T) -> tuple[_T2, _T3]: ...
80+
7181
def eval(src, *args, **kwargs) -> Any: ... # Can't say *anything* about the result -- different from "-> object"
7282
def exec(src, *args, **kwargs) -> NoneType: ...
7383
def execfile(filename: str, *args, **kwargs) -> NoneType: ...

pytype/tests/test_builtins4.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,15 @@ def __index__(self) -> int:
768768
print(x[C()])
769769
""")
770770

771+
def test_divmod(self):
772+
self.Check("""
773+
import datetime
774+
from typing import Tuple
775+
assert_type(divmod(1, 2), Tuple[int, int])
776+
assert_type(divmod(datetime.timedelta(1), datetime.timedelta(2)),
777+
Tuple[int, datetime.timedelta])
778+
""")
779+
771780

772781
class SetMethodsTest(test_base.BaseTest):
773782
"""Tests for methods of the `set` class."""

0 commit comments

Comments
 (0)