Commit Graph

377 Commits

Author SHA1 Message Date
Sebastian Rittau
4b8c37462e Fix decimal (#2323)
* Use Tuple field in DecimalTuple

* Remove unnecessary base classes from Decimal

* Decimal.__init__ -> __new__

* Decimal.__ne__ is not defined in Python 3

* Add Decimal.as_integer_ratio()

* Annotate DecimalException.handle()

* Correct types of Decimal method arguments

* Add missing arguments and optional markers to Decimal

* Add missing arguments to Context

* Remove spurious int from Unions with float

* Remove Context.__setattr__()

* Fix return types of Context methods
2018-07-18 21:59:08 -07:00
Ethan Smith
cc45366ca5 Merge 2/genericpath and 2and3/genericpath (#2330) 2018-07-13 14:07:15 -07:00
Ran Benita
0bc98a18f0 Add stdlib/2and3/imghdr stubs (#2318)
Ad defined in https://docs.python.org/3/library/imghdr.html.
2018-07-10 08:10:25 -07:00
Sebastian Rittau
a38dbc6c1e Merge decimal (#2306) 2018-07-09 19:03:01 -07:00
justinpawela
2a888416b2 Remove annotations from http.HTTPStatus enum members (#2314)
These type annotations are unnecessary and seem to confuse the type system.

* Remove annotation from PlistFormat enum members

Same rationale as python/typeshed#2314; same adverse effects observed.
2018-07-09 18:59:34 -07:00
NAKAMURA Yoshitaka
c78b9eb022 Allow IMAP4.search() to accept "None" charset as docs say (#2310) 2018-07-04 23:24:51 -07:00
Yusuke Miyazaki
6192cce9d9 Avoid using string literals in type annotations (#2294) 2018-07-02 20:23:29 -07:00
Ethan Smith
236ed3f731 Add genericpath stub (#2300)
To backport `os.path.commonpath` in mypy I needed to use genericpath. It seems unchanged since 3.4, and the `same*` functions were added in 3.4. (checked via comparing the `__all__`s of the source in 2.7, 3.4, and 3.7.)
2018-07-02 13:13:38 -07:00
Yusuke Miyazaki
581705d9ee Prefer to use ellipsis over pass (#2292) 2018-06-28 10:29:45 -07:00
Sebastian Rittau
187aaaced9 Use protocols for shutils.copyfileobj() (#2291)
See https://github.com/python/typing/issues/564 for background.
2018-06-28 10:28:24 -07:00
Sebastian Rittau
7ebd609643 Add pyexpat and xml.parsers (#2276) 2018-06-28 10:26:17 -07:00
Sebastian Rittau
b261b228ba Merge Python 2 and 3 shutil (#2259)
* Drop support for Python 3.3
* Merge Python 2 and 3 shutil
* Marked some arguments optional
* Changed callback return type from None to Any for more flexibility
2018-06-27 20:42:58 -07:00
Yusuke Miyazaki
86883d3df9 Remove unused import statements (#2282) 2018-06-27 20:14:57 -07:00
Philipp Hahn
f8041d08db logging.BASIC_FORMAT also for python2.7 (#2283) 2018-06-27 20:14:06 -07:00
Philipp Hahn
4e3b8f7e15 tty.set*() accepts fd or file object (#2285)
<https://docs.python.org/2/library/tty.html>
> ... requires the termios module ...

<https://docs.python.org/2/library/termios.html#module-termios>
> All functions in this module take a file descriptor fd as their first
> argument. This can be an integer file descriptor ... or a file object,
2018-06-27 20:12:04 -07:00
NAKAMURA Yoshitaka
16ed540c95 Fix type for imaplib.IMAP4.error and related (#2273) 2018-06-22 08:43:25 -07:00
John Reese
40b176b195 Fix annotation for difflib.SequenceMatcher.find_longest_match (#2253) 2018-06-20 10:52:39 -07:00
Andrew Svetlov
a5b7ddd96c Accepy bytes in sock.connect() and family (#2252) 2018-06-18 10:30:41 -07:00
Sekou Diao
96e3e23d9b Add locale.windows (#2251)
This is undocumented but it exists (on all platforms AFAICT) and is used, so it should be added, marked `# undocumented`.
2018-06-18 09:19:55 -07:00
strager
e404bc7cd6 Allow pathlib.Path in zipfile.ZipFile (#2238)
`zipfile.ZipFile` is typed to accept `Text` for local and archive file
paths. In Python 3.6, several `ZipFile` methods accept `pathlib.Path`
objects, not just `str` objects. Generalize `ZipFile`'s methods so code
using `pathlib.Path` with `ZipFile` type-checks.

I verified (using my own project) that the following methods work with
os.PurePath at runtime on CPython 3.6:

* zipfile.ZipInfo.__init__
* zipfile.ZipInfo.extractall
* zipfile.ZipInfo.write
2018-06-18 08:29:23 -07:00
Jelle Zijlstra
8084dc1c1f Fix abstract classes in 2.7 (#2247)
Part of #1476.
2018-06-17 17:21:17 +01:00
Jelle Zijlstra
94ab32ba59 Fix abstract classes for Python 3 (#2239)
* add metaclass=ABCMeta to some classes

* mark some more classes as explicitly abstract

* make some more classes concrete
2018-06-16 10:18:54 -07:00
Philipp Hahn
02c42c9cf6 optparse.Values.__getattr__ like argparse.Namespace (#2228)
optparse.Values is like argparse.Namespace and also has a __getattr__() method to return the parsed options.
Apply commits 54b4983 and 9ae0c0b from python/typeshed#25
2018-06-14 06:13:10 -07:00
Anthony Sottile
be3c43cf63 A Thread(target=...) function can return anything (#2224) 2018-06-13 11:50:17 -07:00
Anthony Sottile
c4ee2ed36a Correct annotation for fileinput.input (#2223)
```python
import fileinput

with fileinput.input(files=('foo.txt',), inplace=True, backup='') as f:
    for line in f:
        print(f'prefix{line}', end='')
```

```
$ mypy test2.py
test2.py:3: error: "Iterable[str]" has no attribute "__enter__"; maybe "__iter__"?
test2.py:3: error: "Iterable[str]" has no attribute "__exit__"
```

```
$ mypy test2.py --custom-typeshed typeshed
$
```
2018-06-12 15:45:11 -07:00
Jelle Zijlstra
6bbf3d89eb Further improve codecs stubs (#2217)
- remove header comments
- uppercase type aliases
- remove old-style type annotations
- unquote forward refs
- reformat the file
- remove values for globals
- don't use private names from codecs stub in io.pyi
2018-06-11 22:24:34 -07:00
Roy Williams
52c02a2364 Allow Any type to be acceptable for the msg parameter in `logging.{info, warn, error, ...} (#1776)
The stdlib accepts any value here as long as it is castable to a string:

https://github.com/python/cpython/blob/3.6/Lib/logging/__init__.py#L336
https://github.com/python/cpython/blob/2.7/Lib/logging/__init__.py#L319-L330

Ideally this would use Protocols but I don't see them in use in typeshed yet.
2018-06-11 16:10:31 -07:00
Jelle Zijlstra
bdb06b5b81 improve codecs stubs (#2114)
Started out as progress towards #1476, but I ended up fixing a few more things:
- fixed the signature of _encode_type, which actually returns a pair, not a string
- made some attributes into properties in order to prevent the descriptor protocol from turning them into methods
- found a bug in CPython in the process (python/cpython#6779)

I used the following test file to make sure these classes are now instantiable:

```python
import codecs
import io
from typing import IO

bio = io.BytesIO()
cod = codecs.lookup('utf-8')

codecs.StreamReaderWriter(bio, codecs.StreamReader, codecs.StreamWriter)
codecs.StreamRecoder(bio, cod.encode, cod.decode, codecs.StreamReader, codecs.StreamWriter)
```
2018-06-11 15:53:15 -07:00
Jelle Zijlstra
f65caed181 allow socket.recv_into to take a memoryview (#2127)
Fixes #1862
2018-06-11 14:25:11 -07:00
Jelle Zijlstra
a33a124537 make BZ2File and LZMAFile instantiable (#2115)
Part of #1476.
2018-06-11 13:59:38 -07:00
Yusuke Miyazaki
46a59fc9b1 Add nis stub (#2213) 2018-06-11 11:26:32 -07:00
Scott Belden
84cafafe73 TracebackType is optional (#2202) 2018-06-09 16:22:50 -07:00
Daniel Li
e02eb70cb3 pkgutil.iter_modules accepts iterable of str (#2195) 2018-06-05 09:58:51 -07:00
Michael
9ec6d476c4 Broaden type of val argument to locale.currency (#2192)
Similar to python/typeshed#1350
2018-06-04 07:54:26 -07:00
Stephen Thorne
a25ff0bddf get_grouped_opcodes() returns an iterable of groups, not an iterable of opcodes. (#2183)
The type signature of get_grouped_opcodes() was incorrect. Resulting in type errors when checking return values.

The usage of this function is like this:
groups = sm.get_grouped_opcodes() # groups is Iterable[List[Tuple[str, int, int, int, int]]]
for group in groups:  #  group is List[Tuple[str, int, int, int, int]]
  for opcode in group:  # opcode is Tuple[str, int, int, int, int]
2018-06-01 09:59:57 -07:00
Sebastian Rittau
a3031adb46 Merge Python 2 and 3 SSL stubs (#2175) 2018-05-31 21:44:42 -07:00
Sebastian Rittau
b1cd9fedf8 Complete wsgiref (#2165)
* Add wsgiref.handlers

* Add wsgiref.simple_server
2018-05-28 08:08:27 -07:00
Sushain Cherivirala
226f0553fe Add compact keyword arg to pprint (#2162) 2018-05-24 21:10:17 -07:00
Michael J. Sullivan
c55cf13d8e make difflib use str on 3 and AnyStr on 2 (#2160) 2018-05-24 13:53:42 -07:00
Sebastian Rittau
8b84e9cf13 Improve wsgiref stubs (#2145)
* Use typing.Text

* Add InputStream and ErrorStream WSGI protocols

* Fix return type of WSGIApplication

* Add type hints to wsgiref.validate

* Replace _Bytes by plain bytes

* Add wsgiref.util

* Add wsgiref.headers

* ErrorWrapper.writelines() takes an Iterable

* Fix start_response return type
* Make Python 2 and 3 branches resemble each other more closely
* Use typing.NoReturn
* Fix WriteWrapper.writer type

* Change return type of WriteWrapper.writer to Any
2018-05-23 08:19:07 -07:00
Ilya Konstantinov
128a49a32d Fix LoggerAdapter.process first argument (#2153)
Standard implementation is:
```
def process(self, msg, kwargs):
    kwargs["extra"] = self.extra
    return msg, kwargs
```
so the signature is clearly `(Text, ...) -> (Text, ...)` (or `(str, ...) -> (str, ...)`, but following the other stubs here, I gather it's `Text`).
2018-05-21 08:27:16 -07:00
Michael Lee
709b193416 Rearrange overloads to account for optional arguments (#2150)
Basically, the same thing as [my previous pull request][0], except the
fixes are now focusing on functions with overlapping argument counts.

  [0]: https://github.com/python/typeshed/pull/2138
2018-05-19 09:20:16 -07:00
Dmitry Figol
f7f00c52af socket.create_connection allows host to be None (#2136) 2018-05-17 09:45:59 -04:00
Michael Lee
97d9f2eb2c Ensures overloads are ordered from narrow to broad (#2138)
This commit reorders any overloads where the first overload was
"shadowing" the second, preventing it from ever being matched by type
checkers that work by selecting the first matching overload alternative.

For example, the first overload alternative below is strictly broader
then the second, preventing it from ever being selected:

    class Parent: pass
    class Child(Parent): pass

    @overload
    def foo(x: *int) -> Parent: ...
    @overload
    def foo(x: int, y: int) -> Child: ...

The correct thing to do is to either delete the second overload or
rearrange them to look like this:

    @overload
    def foo(x: int, y: int) -> Child: ...
    @overload
    def foo(x: *int) -> Parent: ...

Rationale: I'm currently [working on a proposal][0] that would amend
PEP 484 to (a) mandate type checkers check overloads in order and
(b) prohibit overloads where an earlier alternative completely shadows
a later one.

  [0]: https://github.com/python/typing/issues/253#issuecomment-389262904

This would prohibit overloads that look like the example below, where
the first alternative completely shadows the second.

I figured it would be a good idea to make these changes ahead of time:
if my proposal is accepted, it'd make the transition smoother. If not,
this is hopefully a relatively harmless change.

Note: I think some of these overloads could be simplified (e.g.
`reversed(...)`), but I mostly stuck with rearranging them in case I was
wrong. The only overload I actually changed was `hmac.compare_digest` --
I believe the Python 2 version actually accepts unicode.
2018-05-17 09:45:33 -04:00
Omar Sandoval
aab1b20c80 Add missing namespace argument to rlcompleter.Completer (#2105)
This argument has been around since 2.3, and it's documented in the
rlcompleter docstring (although not on python.org).
2018-05-09 22:12:02 -07:00
Sebastian Rittau
09008599ce Merge Python 2 and 3 wsgiref (#2106)
* Merge Python 2 and 3 wsgiref

* Move wsigref to 2and3
2018-05-09 16:26:03 -07:00
Andrew Svetlov
142c7488a5 Implement a stub for netrc standard module (#2098) 2018-05-06 10:25:40 +01:00
Emil Hessman
4d8010a988 Define threading.local as a proper class (#2086)
Fixes #1591
2018-04-30 08:48:12 -07:00
Jelle Zijlstra
fc9a822348 specify what type Binary is (#2057)
Fixes python/mypy#4916.
2018-04-27 14:40:33 -07:00
Jelle Zijlstra
46f0bb8b91 support unicode in Python 2 for difflib (#2055)
Fixes #1961.

I mostly just replaced all str annotations with Text, including in return types. This is
only broadly correct; diffing a str and a unicode sequence actually results in a mixed
output of str and unicode. We could also keep the return types as str if using Text
causes errors in real code. For callbacks that take str, I introduced a Union alias
because a callable taking a str would not be a compatible with a parameter of type
Callable[[Text], bool].

I also fixed the return type of difflib.restore.
2018-04-27 14:39:18 -07:00