Jelle Zijlstra
00cda79cf5
add io.TextIOWrapper.read in 3.3 ( #2248 )
...
This is needed to make TextIOWrapper and a few classes that inherit
from it concrete in 3.3. I am actually not sure whether this method
exists at runtime; there's nothing in
https://docs.python.org/3/library/io.html#io.TextIOWrapper
that suggests it was added in 3.4. In any case, it hardly matters
since 3.3 usage should be very rare now.
2018-06-17 23:47:07 +01:00
Jelle Zijlstra
3032fbdff1
make http.client.HTTPResponse concrete in 3.4 ( #2244 )
...
Matches the implementation in https://github.com/python/cpython/blob/3.4/Lib/http/client.py#L308
The ignore works around python/mypy#5027 (commented further up in the 3.5 branch).
Part of #1476 .
2018-06-17 17:29:02 +01:00
Jelle Zijlstra
da8de48f6d
UserList and UserString in 2.7 ( #2246 )
...
Fill out UserList and UserString stubs to make the classes concrete. Compare:
https://github.com/python/cpython/blob/2.7/Lib/UserList.py
https://github.com/python/cpython/blob/2.7/Lib/UserString.py
2018-06-17 17:24:30 +01:00
Jelle Zijlstra
8084dc1c1f
Fix abstract classes in 2.7 ( #2247 )
...
Part of #1476 .
2018-06-17 17:21:17 +01:00
Jelle Zijlstra
6b36b1befe
Iterator provides a concrete __iter__ in 2.7 (#2245 )
...
This is already how it works in the Python 3 stub.
`Iterator.__iter__` also exists at runtime: https://github.com/python/cpython/blob/2.7/Lib/_abcoll.py#L73 .
2018-06-17 12:00:42 +01:00
Jelle Zijlstra
0393de4bd7
fix some abstract classes in Python 2 ( #2240 )
...
Part of #1476 .
2018-06-17 00:56:00 +01:00
Philipp Hahn
7c3edba6ce
python2/gettext improvements ( #2235 )
...
* py2: gettext: info()
returns a Dict[str, str]
<https://docs.python.org/2/library/gettext.html#gettext.NullTranslations.info >
> Return the “protected” _info variable.
<https://docs.python.org/2/library/gettext.html#the-gnutranslations-class >
> The entire set of key/value pairs are placed into a dictionary and set
> as the “protected” _info instance variable.
* py2: gettext: charset()
returns an Optional[str]
<https://docs.python.org/2/library/gettext.html#gettext.NullTranslations.charset >
> Return the “protected” _charset variable.
<https://docs.python.org/2/library/gettext.html#the-gnutranslations-class >
> If the key Content-Type is found, then the charset property is used to
> initialize the “protected” _charset instance variable, defaulting to
> None if not found.
* py2: gettext: [set_]output_charset()
allows to set an Optional[str]
<https://docs.python.org/2/library/gettext.html#gettext.NullTranslations.output_charset >
> Return the “protected” _output_charset variable.
<https://docs.python.org/2/library/gettext.html#gettext.NullTranslations.set_output_charset >
> Change the “protected” _output_charset variable, which defines the
> encoding used to return translated messages.
<https://docs.python.org/2/library/gettext.html#gettext.GNUTranslations.lgettext >
> Equivalent to gettext(), but the translation is returned in the
> preferred system encoding, if no other encoding was explicitly set with
> set_output_charset().
* py2: gettext: install(..., names)
allows to set an Optional[str]
<https://docs.python.org/2/library/gettext.html#gettext.NullTranslations.install >
> If the names parameter is given, it must be a sequence containing the
> names of functions you want to install in the builtins namespace in
> addition to _().
* py2: gettext: localdir=None
is Optional[str]
<https://docs.python.org/2/library/gettext.html#gettext.bindtextdomain >
> If localedir is omitted or None, then the current binding for domain
> is returned.
* py2: gettext: languages=None
is Optional[Sequence[str]]
<https://docs.python.org/2/library/gettext.html#gettext.find >
> If languages is not given, then the following environment variables
> are searched: ...
* py2: gettext: codeset=None
is Optional[str]
<https://docs.python.org/2/library/gettext.html#gettext.translation >
> If provided, codeset will change the charset used to encode translated
> strings.
* py2: gettext: translation(class_=None)
is Optional[type]
<https://docs.python.org/2/library/gettext.html#gettext.translation >
> The actual class instantiated is either class_ if provided, otherwise
> GNUTranslations.
* py2: gettext: translation(fallback)
is bool
<https://docs.python.org/2/library/gettext.html#gettext.translation >
> ..., this function raises IOError if fallback is false (which is the
> default), and returns a NullTranslations instance if fallback is true.
* py2: gettext: install(unicode)
is bool
<https://docs.python.org/2/library/gettext.html#gettext.install >
> The unicode flag is passed to the resulting translation object’s
> install() method.
which is already expecting `bool`.
2018-06-16 10:19:24 -07: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
Jelle Zijlstra
341fa375ef
cleanup in typing.pyi ( #2241 )
...
- Fix TODOs around TracebackType
- Don't use quotes for forward references
- Make Generator and AsyncGenerator attributes into properties
2018-06-16 08:24:52 -07:00
Jelle Zijlstra
c06a718c5b
always run mypy with --no-implicit-optional ( #2242 )
...
This was already the configuration in Travis and it's been working fine. It's
confusing that Travis was using a different configuration than the default
when you run tests/mypy_test.py yourself.
2018-06-15 21:34:14 -07:00
Jelle Zijlstra
499f852e37
add --show-traceback to mypy_test.py flags ( #2236 )
...
This makes debugging easier.
2018-06-15 16:46:59 -07:00
Daniel Li
5054465746
Make concurrent.futures stubs identical ( #2237 )
...
Make the Python 2 and 3 concurrent.futures stubs identical so fixes get
applied to both.
For example, #1305 and #2233 fixed the same problem at different times,
as did #1078 and #1911 .
By making the stubs identical, we apply the fix from #1711 to Python 2.
Fixes #2234 .
2018-06-15 10:03:19 -07:00
Daniel Li
a9366df7e8
Improve signatures in concurrent.futures backport ( #2233 )
...
Use parameterized types in Future.add_done_callback(), wait(), and
as_completed().
Mark the traceback argument to Future.set_exception_info() as optional.
2018-06-15 08:21:01 -07:00
Anthony Sottile
56c93c85c0
Add NoReturn to execv* family of functions ( #2226 )
2018-06-15 07:55:45 -07:00
Rebecca Chen
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
Jason Fried
451deba4ef
memoryview type information inconsistent with runtime behavior ( #2230 )
...
memoryview type information inconsistent with documentation of typing module.
`memoryview` should be a ByteString like the docs say.
`memoryview.__init__` does not accept str, and instead of a union it should just accept ByteString.
`memoryview.__iter__` returns an Iterator[int] not bytes.
2018-06-15 07:51:56 -07:00
Anthony Sottile
395ab5abd1
Values of data are Optional ( #2231 )
2018-06-15 07:48:55 -07:00
Bertrand Bonnefoy-Claudet
4b5a63d10f
Fix werkzeug.wrappers.BaseResponse.__init__ ( #2232 )
...
This additionally allows strings, bytearrays and string iterables to be
passed as the `response` argument of `BaseResponse` (and thus also
`Response`).
Strings and bytearrays are explicitly handled in `__init__` [1].
Strings are also featured on the Werkzeug front-page snippet (`'Hello
World!'`) [2].
[1]: d129d17066/werkzeug/wrappers.py (L861)
[2]: http://werkzeug.pocoo.org/
2018-06-15 07:24:22 -07:00
Bertrand Bonnefoy-Claudet
15ad132393
Werkzeug stub fixes ( #2229 )
...
* Fix stub for werkzeug.exceptions.Aborter and abort
* `werkzeug.exceptions.abort` [1] was missing and is thus added here.
It's also commonly used in Flask as `flask.abort`.
* They both always raise [2], hence the `NoReturn` return type.
[1]: http://werkzeug.pocoo.org/docs/0.14/exceptions/#werkzeug.exceptions.abort
[2]: d129d17066/werkzeug/exceptions.py (L708-L713)
* Fix stub for werkzeug.wrappers.AuthorizationMixin
The code [1] uses `@cached_property` [2], which is basically a Python
property, and optionally returns an `Authorization` [3] object.
[1]: d129d17066/werkzeug/wrappers.py (L1462-L1466)
[2]: d129d17066/werkzeug/utils.py (L35)
[3]: d129d17066/werkzeug/datastructures.py (L2438)
2018-06-14 09:04:18 -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
Martin DeMello
caff008ff2
test files under stdlib/2and3 with both python versions ( #2222 )
...
* test files under stdlib/2and3 with both python versions
2018-06-12 15:48:00 -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
de86f15fa0
Make http.client.HTTPResponse a BinaryIO ( #2218 )
...
Fixes #2189 .
The errors from mypy are a false positive (see python/mypy#5027 ).
2018-06-12 09:20:24 -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
Ilya Konstantinov
978c0913c8
Add stub for first ( #2141 )
...
Reviewed by author in https://github.com/hynek/first/pull/22
2018-06-11 19:50:56 -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
Max
a753abafcf
Fix click.getchar return type ( #1473 )
2018-06-11 15:54:56 -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
d2469c0e89
fix type for itertools.product ( #2129 )
...
Fixes #1850 .
The fix was already applied to Python 2, but the typevar-based solution there
leads to "cannot infer value of type variable" in mypy. I used the following
script to check:
```python
from itertools import product
reveal_type(product([1]))
reveal_type(product([1], ['x'], [False], [3.0], [(1,)], [('x',)], [{1}], [{1: 2}], repeat=5))
```
2018-06-11 15:52:44 -07:00
Jelle Zijlstra
ced5d61bb6
make urllib.response.addinfourl instantiable ( #2134 )
...
Fixes #1377 (because HTTPError is a subclass of addinfourl). Also part of #1476 .
2018-06-11 15:43:53 -07:00
Guido van Rossum
c4bf27b835
Copy __builtin__.pyi to builtins.pyi, to fix breakage caused by #2128 ( #2215 )
2018-06-11 15:10:22 -07:00
Jelle Zijlstra
4e6af84640
improve multiprocessing.Pool types ( #2126 )
...
Fixes #1703
Mostly introduce typevars to express that the return types match the return types of the
callbacks.
Removed comment about incompleteness since all documented classes from
https://docs.python.org/3/library/multiprocessing.html#module-multiprocessing.pool
are covered.
2018-06-11 14:42:57 -07:00
Jelle Zijlstra
82c930e66c
Improve asyncio.tasks stubs ( #2139 )
...
- Use PEP 526-style variable annotations where possible
- Use FrameType instead of Any
- Remove workaround for mypy issue that was since fixed
2018-06-11 14:40:54 -07:00
Jelle Zijlstra
f5a74fd5da
remove Optional from type of __slots__ ( #2128 )
...
Fixes #1853
2018-06-11 14:29:11 -07:00
Guido van Rossum
c5e98308c0
Copy stdlib/3.4/enum.pyi to third_party/3/enum.pyi to satisfy tests ( #2214 )
...
Fix test breakage caused by #2118 .
2018-06-11 14:28:47 -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
cb293ebd2e
switch order of base classes on awaitable classes ( #2125 )
...
Fixes #1940 .
This makes it so that mypy will infer the common base class of these
classes to be Awaitable instead of Iterable. I verified that this
fixes the errors in the script posted by @neilconway.
2018-06-11 14:20:31 -07:00
Jelle Zijlstra
7abcd0f71f
add ConfigParser.readfp in Python 3 ( #2123 )
...
https://docs.python.org/3/library/configparser.html#configparser.ConfigParser.readfp
Fixes #2112
2018-06-11 14:10:52 -07:00
Jelle Zijlstra
53fde2ddf7
make timeout argument to Connection.poll Optional ( #2122 )
...
Fixes #2094
2018-06-11 14:04:45 -07:00
Jelle Zijlstra
91af6291b1
make shlex.shlex and multiprocessing.pool.IMapIterator instantiable ( #2120 )
...
Part of #1476 .
2018-06-11 14:04:05 -07:00
Jelle Zijlstra
c5bc3bd7fa
make contextvars.Context instantiable ( #2119 )
...
Part of #1476 .
2018-06-11 14:03:02 -07:00
Jelle Zijlstra
f789ee25ad
make EnumMeta instantiable ( #2118 )
...
part of #1476 . Verified that len(Enum) is still allowed by mypy.
2018-06-11 14:02:16 -07:00
Jelle Zijlstra
f73351f5bf
make tracemalloc.Traceback instantiable ( #2117 )
2018-06-11 14:01:46 -07:00
Jelle Zijlstra
28f6c095d4
make http.cookies.{Base,Simple}Cookie instantiable ( #2116 )
...
Part of #1476 .
2018-06-11 14:01:17 -07:00
Jelle Zijlstra
a33a124537
make BZ2File and LZMAFile instantiable ( #2115 )
...
Part of #1476 .
2018-06-11 13:59:38 -07:00
Jelle Zijlstra
764ee4eeec
add pytz.ZERO and pytz.HOUR ( #2180 )
...
https://github.com/stub42/pytz/blob/master/src/pytz/__init__.py#L187
2018-06-11 11:27:34 -07:00
Yusuke Miyazaki
46a59fc9b1
Add nis stub ( #2213 )
2018-06-11 11:26:32 -07:00
Jelle Zijlstra
38fb53eab6
add __init__ to SimpleNamespace ( #2207 )
...
```In [11]: SimpleNamespace(x=3)
Out[11]: namespace(x=3)
```
2018-06-11 08:08:41 -07:00
Daniel Li
87c296c964
Some inspect.formatargspec args cannot be None ( #2212 )
...
The annotations, formatarg, formatvarargs, formatvarkw, formatvalue,
formatreturns, and formatannotations arguments to inspect.formatargspec
have default values, but they cannot be None.
2018-06-11 08:07:47 -07:00