Commit Graph
81 Commits
Author SHA1 Message Date
Rebecca ChenandGitHub 8ecf3ff0b6 Make the start argument to itertools.count optional. (#5332)
start should be optional: https://docs.python.org/3.8/library/itertools.html#itertools.count
Directly changing the second overload to mark start as optional
generated a mypy error about overlapping overloads, but adding a third
overload seems to work.

I also noticed that `_NStep` was defined as a TypeVar when I think it
makes more sense for it to be a Union, so I went ahead and changed that
as well.
2021-05-03 16:34:03 -07:00
Rebecca ChenandGitHub 2682c1d00a Let xml.dom.minidom.parse() accept files. (#5005)
The documentation says, "The parse() function can take either a filename
or an open file object."
(https://docs.python.org/3.8/library/xml.dom.minidom.html). The function
was annotated as only accepting a str, so I added IO[Any].
2021-02-04 16:01:55 -08:00
Rebecca ChenandGitHub 569fcea637 Switch back to installing the released version of pytype. (#4985)
pytype-2021.01.28 contains the changes needed to support the new
typeshed directory structure.
2021-01-29 09:15:54 +01:00
Rebecca ChenandGitHub ce24720a1a Fix and re-enable pytype_test (#4975)
For now, the test requires changes that have been merged into the pytype master branch but not yet released. I'll update requirements-tests-py3.txt again once I've cut a new release (hopefully later this week).

* Fix pytype_test.
* Re-enable pytype_test.
* Remove continue-on-error from pytype_test.
* Temporarily install pytype from its master branch, as the code to
  support the new directory structure hasn't been released yet.
* Set TYPESHED_HOME before using pytype.pytd.Typeshed().
2021-01-27 22:00:27 +00:00
Rebecca ChenandGitHub a7c4663e39 Speed up pytype_test by reusing the pyi loader. (#4960)
I noticed that the pytype parse test was getting quite slow again. This
is a somewhat hacky change that caches pytype's internal pyi loader to
avoid parsing files multiple times. On my machine, the test goes from
taking ~6m to complete to ~30s.
2021-01-21 18:44:06 -08:00
Rebecca ChenandGitHub 5cf4f77401 Add undocumented telnetlib.Telnet attribute. (#4932)
A pytype user reported it missing:
https://github.com/google/pytype/issues/590.
2021-01-13 16:57:00 -08:00
Rebecca ChenandGitHub 94b7eac675 Reference a class in importlib.metadata by its fully qualified name. (#4908)
See https://github.com/google/pytype/issues/779.

In Python 3.8, pytype fails to parse this file because it can't find
Context. This wasn't caught by pytype_test because the test runs in
Python 3.6.
2021-01-05 22:39:24 +01:00
Rebecca ChenandGitHub 7489e1b9c2 Remove __del__ from the tkinter _Image protocol. (#4909)
See https://github.com/python/typeshed/pull/4766#issuecomment-753341778.
2021-01-05 22:38:41 +01:00
Rebecca ChenandGitHub 61c5667b3f Fix a Python 2 annotation in shlex. (#4805)
https://github.com/python/cpython/blob/8d21aa21f2cbc6d50aab3f420bb23be1d081dac4/Lib/shlex.py#L24
suggests instream can be a string as well.
2020-12-07 14:27:56 -08:00
Rebecca ChenandGitHub 8c20938ba1 Add an _Image protocol to tkinter. (#4766) 2020-11-13 20:59:29 +01:00
Rebecca ChenandGitHub a42f545215 Change some tkinter function parameter types from bool to int. (#4765)
Change some tkinter function parameter types from bool to int.

Based on the fact that tk.{YES,NO,TRUE,FALSE} are defined as ints
and that the usage example in the source code also uses an int as a bool.
2020-11-13 11:34:39 +01:00
Rebecca ChenandGitHub fff7a10ae7 Add a version guard for importing enum in pstats. (#4635)
* Add a version guard for importing enum.

I'm trying to pull the latest version of typeshed into Google, and
pytype chokes on pstats in Python 2 because the enum module was
introduced in 3.4.

* Move the enum import into the branch that defines SortKey.
2020-10-08 16:09:24 -07:00
Rebecca ChenandGitHub 9dbe7f348f Update pytype to a version that can parse six. (#4546) 2020-09-17 05:46:27 +02:00
Rebecca ChenandGitHub 2587c93ff8 Stop passing python_exe to pytype_test. (#4488)
pytype hasn't needed the python_exe argument for a while, and getting
rid of it allows some code to be deleted.
2020-08-27 19:19:49 -07:00
Rebecca ChenandGitHub 61537be530 Upgrade the pytype version to one that can parse the tkinter stubs. (#4456)
The latest pytype release fixes two pyi parser bugs that allow files
affected by them to be taken off the pytype exclude list. I removed two
`total=False` declarations in tkinter/__init__ that pytype does not like
(because it checks that `total` is present only when TypedDict is a
class's immediate parent) and which shouldn't be needed because
_InMiscNonTotal already specifies totality. I double-checked that mypy
reports no errors in 3.7 on a .py file containing:

  from typing_extensions import TypedDict
  Foo = TypedDict('Foo', {'x': int}, total=False)
  class Bar(Foo): pass
  x: Foo = {}

showing that it doesn't require `total` to be repeated.
2020-08-17 19:49:58 -07:00
Rebecca ChenandGitHub f9acd5aa3b Mark http.server.SimpleHTTPRequestHandler's directory arg as optional. (#4443)
`directory` has a default value:
https://docs.python.org/3/library/http.server.html#http.server.SimpleHTTPRequestHandler.
2020-08-12 17:59:00 -07:00
Rebecca ChenandGitHub 537b730558 Update to pytype 2020.07.20 and remove nmap from the exclude list. (#4348) 2020-07-20 23:01:21 -07:00
Rebecca ChenandGitHub 5fe6a5ba8b parser: STType.compile() can be called with no arguments. (#4034)
The filename parameter is optional:
https://docs.python.org/3/library/parser.html#parser.ST.compile.
2020-05-18 08:30:52 -07:00
Rebecca ChenandGitHub 037377f502 Mark the arguments to os.killpg as positional-only in Python 2. (#4033)
This was already done in Python 3. In Python 2 as well, this method does
not take keyword arguments.
2020-05-17 18:06:35 -07:00
Rebecca ChenandGitHub a70f4893f8 Add undocumented attribute queue.Queue.queue with type Any. (#4032)
This attribute was removed in
https://github.com/python/typeshed/pull/3879 because it is undocumented
and was annotated incorrectly. Unfortunately, a surprising (?) amount of
Google code uses this attribute and assumes it is a deque, so it needs
to exist but can't have a more general annotation like Collection[Any].

I also removed a no-longer-used typing.Deque import.
2020-05-17 18:05:52 -07:00
Rebecca ChenandGitHub 53f4f68d71 saxutils.XMLGenerator should accept unicode encodings in Python 2. (#4031) 2020-05-17 18:05:21 -07:00
Rebecca ChenandGitHub 8366aa44bb Add mistakenly removed constants back to tokenize. (#4030)
These constants were removed in
https://github.com/python/typeshed/pull/3839 because they are imported
from token. However, that is only true in Python 3.7+.
2020-05-17 18:05:07 -07:00
Rebecca ChenandGitHub b8b656b437 Import builtins._PathLike instead of os.PathLike in genericpath. (#4013)
os imports genericpath, so genericpath importing os creates a circular
import that confuses pytype.
2020-05-16 16:56:40 -07:00
Rebecca ChenandGitHub af01f1f4be uuid: import enum inside version check. (#4009)
Otherwise, pytype tries to import enum in Python 2 and complains that
the library doesn't exist.
2020-05-17 01:32:07 +02:00
Rebecca ChenandGitHub 37051ec699 Have datetime.{date,datetime} define __new__ instead of __init__. (#3829)
This is more faithful to the implementation:
https://github.com/python/cpython/blob/3.5/Lib/datetime.py.

When these classes define __init__, pytype has trouble type-checking
classes that inherit from datetime.datetime (done in, e.g., the third party
datetime_tz library) because it gets confused about what arguments the
constructor expects.
2020-03-07 12:52:04 +01:00
Rebecca ChenandSebastian Rittau 3b3fc6a57f Make os.statvfs_result inherit from typing.NamedTuple. (#3603) 2020-01-10 22:42:29 +01:00
Rebecca ChenandJelle Zijlstra e0151e724a Make unittest.FunctionTestCase inherit from TestCase in Python 2. (#3597)
This makes the pyi file match the implementation:
https://github.com/python/cpython/blob/249706c1fbce04125d81bd9993e6c010ae30f8e4/Lib/unittest/case.py#L1019.

I also removed a now-redundant `run` method from FunctionTestCase
because the mypy test complained about it having a different signature
from TestCase.run().

Context:
https://github.com/python/typeshed/pull/3550#issuecomment-572702513.
2020-01-09 13:04:08 -08:00
Rebecca ChenandGitHub 1651348a08 Require a newer version of pytype that supports @type_check_only. (#3593) 2020-01-08 17:15:25 -08:00
Rebecca ChenandSebastian Rittau 3fbebc78cb Require a more recent pytype version. (#3388)
Yesterday's release contains a number of pyi parser fixes, such as
support for the syntax in #3321.
2019-10-18 23:21:53 +02:00
Rebecca ChenandSebastian Rittau ffd73b3e8e Add shlex.shlex.next in Python 2. (#3389)
shlex.shlex should match the Iterator protocol, for which it needs both
`__iter__` and `__next__` (`next` in Python 2) defined.
2019-10-18 23:13:38 +02:00
Rebecca ChenandGitHub 90aa27b54a Fix the signature of IOBase._checkClosed(). (#3305)
* In Python 2, the optional `msg` argument was missing.
* In Python 3, the method was missing altogether.

Reference:
https://github.com/python/cpython/blob/2.7/Lib/_pyio.py#L423
https://github.com/python/cpython/blob/3.6/Lib/_pyio.py#L443
2019-10-04 14:53:48 -07:00
Rebecca ChenandSebastian Rittau ac35a18ad6 Make the value argument to ctypes.cbool.__init__ optional. (#3273) 2019-09-28 00:39:04 +02:00
Rebecca ChenandSebastian Rittau 3f8c2169d1 Define listdir in posix and import it in os. (#3258) 2019-09-23 23:41:05 +02:00
Rebecca ChenandSebastian Rittau 0602840cc2 Make the type of timeout Optional[float] everywhere in subprocess. (#3241) 2019-09-18 11:05:49 +02:00
Rebecca ChenandSebastian Rittau 9488b58fb3 Copy a better definition of abstractmethod from 3/abc to 2/abc. (#3242) 2019-09-18 11:04:53 +02:00
Rebecca ChenandSebastian Rittau abc241bd35 Use Literal to improve tempfile.[Named]TemporaryFile. (#3215) 2019-08-31 11:25:44 +02:00
Rebecca ChenandGitHub 03b38d4d2e Add sys.flags.utf8_mode. (#3205)
This is new in Python 3.7:
https://docs.python.org/3/library/sys.html#sys.flags
2019-08-23 12:06:21 -07:00
Rebecca ChenandJelle Zijlstra fab2ee0d7c Remove unnecessary quotes around forward references. (#3191) 2019-08-16 20:29:32 -07:00
Rebecca ChenandJelle Zijlstra b873894e16 Fix a typo (self -> cls) in stdlib/2/subprocess.pyi. (#3185) 2019-08-14 18:14:30 -07:00
Rebecca ChenandSebastian Rittau 6f01493edc Move some constants from tokenize to token in Python 3.7+. (#3175) 2019-08-08 08:45:08 +02:00
Rebecca ChenandJelle Zijlstra c3b70d4224 Require the newest pytype version, with a pyi parser fix. (#3160)
For https://github.com/python/typeshed/pull/3149.
2019-07-30 13:50:51 -07:00
Rebecca ChenandJelle Zijlstra c356316c6f Use pytype.config.Options.create() for prettier code. (#3151)
This is a small cosmetic change. I want to encourage use of the
nicer-lookng pytype.config.Options.create() rather than
direct construction of the command-line args, so I'm changing
over all occurrences of the latter that I can find.
2019-07-25 19:43:33 -07:00
Rebecca ChenandGitHub 40124b5f4c Update required pytype version to one that supports async def. (#3112) 2019-07-11 12:47:46 -07:00
Rebecca ChenandGitHub 5dc89fe8cf Add undocumented methods codecs.utf_16_be_{decode,encode}. (#3091)
I found the signatures here:
https://github.com/python/cpython/blob/6a16b18224fa98f6d192aa5014affeccc0376eb3/Modules/_codecsmodule.c#L729

https://github.com/google/pytype/issues/348 was opened against
pytype about utf_16_be_encode being missing.
2019-06-26 20:29:16 -07:00
Rebecca ChenandJelle Zijlstra d64a26cf99 Add missing constructor to types.CodeType. (#3040)
I got the argument order from
https://github.com/python/cpython/blob/2bfc2dc214445550521074f428245b502d215eac/Objects/codeobject.c#L263
and the types from the attributes already in the stub.
2019-06-08 07:07:29 -07:00
Rebecca ChenandJelle Zijlstra e7184d6dfc Add undocumented but used method LWPCookieJar.as_lwp_str. (#3041)
The method is defined here:
https://github.com/python/cpython/blob/e36ed475ea429f7cc80a4d65f80b44686a74b246/Lib/http/cookiejar.py#L1864
2019-06-08 07:06:14 -07:00
Rebecca ChenandSebastian Rittau f8093d63cd Move stdlib/3/curses to stdlib/2and3/curses. (#3025)
Also add the A_ITALIC constant, which is new in 3.7.
2019-06-01 10:51:07 +02:00
Rebecca ChenandGitHub 78982de5be Remove all pyi files that use nested classes from the pytype blacklist. (#2993)
We finally support this!
2019-05-15 14:53:13 -07:00
Rebecca ChenandGitHub aa4a84ef3f Always use fully qualified names to refer to nested classes. (#2983)
The main purpose of this change is to get the stubs into a
form that pytype will support with its next release. Since
these stubs already mostly use fully qualified names, this
will also increase consistency.
2019-05-12 15:10:48 -07:00
Rebecca ChenandJelle Zijlstra 5799b8dfcf Unblacklist more third_party stubs from pytype parsing. (#2975) 2019-05-08 20:18:08 -07:00
Rebecca ChenandSebastian Rittau 4990830c8f Make pytype happy with the third_party click stubs. (#2966)
This also makes the flask stubs that depend on click parseable.

* In pytype_test, only parse files with the .pyi extension.
  (There's a README in third_party/2and3/click/.)
* Annotate with ContextManager rather than using the
  contextmanager decorator. This is shorter, removes a
  dependency, and gets rid of the slight weirdness of a
  decorator needing to be evaluated in a stub.
* Fix non-stub things.
2019-05-07 08:50:24 +02:00
Rebecca ChenandGitHub a6d92eca10 Adjust indentation of TODOs in third_party/2/gflags.pyi. (#2964)
Having TODOs at a different level of indentation than
the surrounding lines trips up pytype.
2019-05-06 22:05:17 -04:00
Rebecca ChenandJelle Zijlstra 7c475a48d7 Fix typo: __builtins__ should be __builtin__. (#2963) 2019-05-06 22:00:02 -04:00
Rebecca ChenandJelle Zijlstra 1379fdcdd9 Remove some files from pytype's third_party blacklist. (#2962)
Removes files that are parseable with the most recent release.
2019-05-06 21:59:12 -04:00
Rebecca ChenandJelle Zijlstra 5081d1e132 Switch pytype_test from a whitelist to a blacklist for third_party. (#2956)
During the PyCon sprints, I'm planning to bash the pytype pyi
parser into shape so we can handle all of third_party. As a first
step, create an explicit blacklist of everything pytype chokes on.
2019-05-05 22:02:52 -04:00
Rebecca ChenandSebastian Rittau fd57aee5da Make shlex.shlex convertable to a list in Python 2. (#2927)
This simply copies the relevant lines over from the Python 3 stub.
2019-04-21 09:21:00 +02:00
Rebecca ChenandSebastian Rittau 50a661afed Complete the stub for _thread.pyi. (#2900)
Definitions based on https://docs.python.org/3/library/_thread.html.
2019-04-09 20:02:04 +02:00
Rebecca ChenandGitHub a651e2f3cd Update pytype_test to remove now-unnecessary parse-only functionality. (#2897)
With today's release, pytype is able to fully load
stdlib/3/collections/__init__.pyi, so the test no longer needs the
ability to partially parse stubs using the pytd tool. Removing this
functionality allows the test code to be simplified considerably.
2019-04-03 12:47:20 -07:00
Rebecca ChenandSebastian Rittau 9b9ff64fc5 tempfile.mkdtemp() should return a str when passed no arguments. (#2893)
Otherwise, pytype expands `AnyStr` to `Union[str, bytes]`, leading
to spurious type errors later on.

* Mark the `dir` argument to mkdtemp as AnyStr.
2019-03-29 23:11:42 +01:00
Rebecca ChenandGitHub a1d1870779 Fix a py2 parameter type in string.Template.(safe_)substitute. (#2888)
Context: https://github.com/python/typeshed/pull/2871#issuecomment-476806895
2019-03-26 23:25:15 -07:00
Rebecca ChenandSebastian Rittau 7c80c52a7a Add missing class pdb.Pdb. (#2872)
Based on: https://docs.python.org/3/library/pdb.html#pdb.Pdb,
with the one difference that the `skip` argument to the
constructor is present in 2.7 despite being listed as new in 3.1.
2019-03-16 22:14:16 +01:00
Rebecca ChenandSebastian Rittau e541cdd1a6 Add unicode support to py2 string.Template. (#2871) 2019-03-16 22:12:36 +01:00
Rebecca ChenandSebastian Rittau 03878d732a Add attribute queue.Queue.queue. (#2870) 2019-03-16 22:11:48 +01:00
Rebecca ChenandSebastian Rittau 437d8e0ddd Add tarfile.filemode. (#2869)
This function is defined up to Python 3.7 (albeit deprecated in Python 3).
2019-03-16 09:45:01 +01:00
Rebecca ChenandSebastian Rittau 8c252052f9 Move pydoc from 2/ to 2and3/. (#2873) 2019-03-16 09:37:24 +01:00
Rebecca ChenandSebastian Rittau 4743d2521a Remove asyncio.tasks from the pytype blacklist. (#2874)
With version 2019.03.15, pytype is able to parse this file.
2019-03-16 09:35:30 +01:00
Rebecca ChenandGitHub 45e52de188 Speed up pytype_test by reducing subprocess calls. (#2868)
Speeds up pytype considerably by directly calling pytype.io.parse_pyi
rather than running `pytype --parse-pyi` in a subprocess.
The subprocess logic is still required to handle the one pyi file
marked `# parse only` in the pytype blacklist. Once
https://github.com/google/pytype/issues/242 is fixed, the test code
can be cleaned up considerably.
2019-03-14 19:04:40 -07:00
Rebecca ChenandSebastian Rittau 7b6bb60fe2 Remove an unused import from stdlib/3/importlib/__init__.pyi. (#2866)
pytype has trouble resolving unused imports, since it looks at usage
to distinguish submodules from other imports.
2019-03-14 19:51:19 +01:00
Rebecca ChenandJelle Zijlstra 3f8c08402d Remove an unnecessary entry from the pytype blacklist. (#2799) 2019-02-15 17:33:29 -08:00
Rebecca ChenandJelle Zijlstra d275e73e1f Remove pytype workaround in os/__init__.pyi. (#2797)
Pytype release 2019.02.13 fixed the bug that
necessitated this workaround.
2019-02-14 12:29:19 -08:00
Rebecca ChenandJelle Zijlstra 3d8a8ec45d Fix py3 types of inspect.FullArgSpec.var(args|kw) (#2556) 2018-10-25 10:45:59 -07:00
Rebecca ChenandSebastian Rittau ea0a0fd17e Fix _StrType in difflib in Python 2. (#2514)
difflib functions accept unicode as well.
2018-10-12 14:39:24 +02:00
Rebecca ChenandJelle Zijlstra 9fda6b20ec Make the signature of optparse.OptionParser.parse_args more precise. (#2464) 2018-09-25 21:15:10 -07:00
Rebecca ChenandJelle Zijlstra cfa52c7c38 Add a stub for google.protobuf.json_format. (#2479) 2018-09-25 21:03:27 -07:00
Rebecca ChenandGitHub eb09e2898b Update pytype_test to be easier to run manually. (#2469)
* Moves the pytype installation to requirements-tests-py3.txt, now
  that pytype can run under Python 3.5+.
* Changes tests/pytype_test.py to not require a --python{version}-exe
  argument when it can automatically find the Python interpreter, and
  cleans up a few typos and out-of-date things.
* Updates the appropriate documentation.
* Updates .travis.yml.
2018-09-21 09:38:33 -07:00
Rebecca ChenandSebastian Rittau b7c262523b Fix the Python 2 signature of tempfile._TemporaryFileWrapper.write. (#2465) 2018-09-18 13:54:56 +02:00
Rebecca ChenandSebastian Rittau 7dbc8748dc Add __iter__ method to codecs.StreamReader. (#2463) 2018-09-18 13:46:16 +02:00
Rebecca ChenandSebastian Rittau 9e72a7fd0c Fix the return type of decimal.Decimal.__new__. (#2458) 2018-09-15 18:12:52 +02:00
Rebecca ChenandSebastian Rittau 77e4d5d5a8 Add six.moves.urllib_request and six.moves.urllib_response. (#2455) 2018-09-13 22:01:56 +02:00
Rebecca ChenandJelle Zijlstra a08c6eae23 Add two more third_party libraries to pytype_test. (#2437) 2018-09-07 23:42:24 -07:00
Rebecca ChenandJelle Zijlstra ff821f9751 Update pytype_test and pytype_blacklist (#2225)
* Add parts of third_party/ to pytype_test.

Pytype uses six and mypy_extensions, so these pyi files should be
tested with pytype.

* Remove newly loadable pyi files from pytype_blacklist.
2018-06-15 07:53:17 -07:00