Commit Graph

402 Commits

Author SHA1 Message Date
Michael J. Sullivan
ffeede30d2 Make SyntaxError.offset be optional (#2557) 2018-10-25 13:54:55 -07:00
Sebastian Rittau
006a79220f Flake8 fixes (#2549)
* Fix over-indented continuation lines

* Fix under-indented continuation lines

* Fix whitespace around default operator problems

* Limit line lengths

* Fix inconsistent files
2018-10-24 07:20:53 -07:00
Michael J. Sullivan
4badd35325 Allow json.dump to dump to BinaryIO again (#2546)
PR #2516 aimed to widen the accepted file argument to json.dump, but
since `IO` is invariant in its argument, it actually disallowed
passing binary files.
2018-10-23 16:13:07 -07:00
Jelle Zijlstra
63cf7f529b fix lint error (#2541) 2018-10-23 14:00:26 +02:00
Dave Halter
a437fcc886 Add attributes to int and float (#2529)
* real, imag, conjugate all exist on int and float
* numerator, denominator exists on int
2018-10-23 00:44:36 +02:00
Lourens Veen
703c03e4b0 Add UserString and UserList data attribute (#2518) 2018-10-16 10:36:17 +02:00
Siva Chandra
cec2202550 Widen the type of the file argument to Python 2's json.dump. (#2516) 2018-10-12 15:58:46 -07:00
Semyon Proshev
4859742087 Inherit InstanceType from object (#2511) 2018-10-08 14:31:21 +02:00
Jelle Zijlstra
bc3f9fe1d3 fix typing.Pattern in Python 2 (#2219)
Fixes #2199
2018-10-01 20:35:13 -07:00
Richard Levasseur
4122a70648 Add some private methods to unittest (#2494)
This adds a few stubs that are used by absl-py, and, without them, cause
type checker errors under Pytype:
 * TestCase._formatMessage
 * TestCase._testMethodName
 * TestCase._getAssertEqualityFunc
 * TestProgram.runTests
2018-10-01 20:18:26 -07:00
Israel Tsadok
2a30462c4a The filter function may return str, tuple or list (#2472)
In Python 2, the return type of filter depends on the iterable
parameter.
2018-09-25 20:26:23 -07:00
Michael J. Sullivan
65863bebf4 make __class__ refer to the current object's class (#2480)
This is just a direct rehash of #1549.
2018-09-25 18:04:37 -07:00
Michael R. Crusoe
2e0af18dda slices of MutableSequences are also MutableSequences (#2428) 2018-09-25 13:06:59 -07:00
Sebastian Rittau
ea2122741f os.path.exists (Py 3) accepts a file descriptor (#2451)
Closes #1653
2018-09-24 07:53:44 -07:00
Michael J. Sullivan
4f4a025409 Remove tuple's __init__ method (#2467)
The __new__ method should suffice, and having both interferes with providing
a __new__ in namedtuples, which we want to do to fix
https://github.com/python/mypy/issues/1279.
2018-09-18 20:01:14 -07:00
Rebecca Chen
b7c262523b Fix the Python 2 signature of tempfile._TemporaryFileWrapper.write. (#2465) 2018-09-18 13:54:56 +02:00
Sebastian Rittau
44bdf6c6c7 Fix RawConfigParser.readfp() annotation (#2443)
Closes #689
2018-09-11 08:22:36 -07:00
Jelle Zijlstra
8b9e4c378a fix module argument to unittest.main (#2403) 2018-09-10 11:04:05 -07:00
Ilya Konstantinov
fe04d3aa2d Accept str in cast (#2408) 2018-08-21 07:53:35 -07:00
Jelle Zijlstra
9e023e7586 minor namedtuple fixes (#2227)
- The extra arguments aren't keyword-only in 2.7.
- Added the `defaults` argument in 3.7 (https://docs.python.org/3.7/library/collections.html#collections.namedtuple).
2018-08-19 03:47:10 +01:00
Teddy Sudol
0386f3daec Change mode: unicode to mode: Text (#2398)
Resolves #2397
2018-08-17 16:33:35 -07:00
Sebastian Rittau
25ac4d6af4 Implement StartResponse using a protocol (#2392)
* Add ExcInfo and OptExcInfo type aliases

* Implement StartResponse using a protocol

* Mark stub-only types with an underscore

* Remove wrong TODO note

python/mypy#1178 is about variable-length tuples, while exc_info()
always returns a tuple with length 3. Ideally, exc_info() would
return Union[Tuple[Type[_E], _E, TracebackType], Tuple[None, None, None]],
but that is a different issue.
2018-08-17 08:36:00 -07:00
Michael Lee
bc8d68cd34 Add constructor for HTTPError in urllib2/urllib.error (#2373)
It seems that code using HTTPError previously worked by accident
because we used to accept arbitrary keyword arguments when
instantiating BaseException, or any subclass of BaseException
(see https://github.com/python/typeshed/pull/2348).

This commit adds in the correct constructor (which also lets the
user specify the arguments in keyword-argument form).

Note: I'm not very familiar with the urllib libraries, so I opted
to just add the signature and leave it up to somebody else to
fill in the types.
2018-08-08 17:05:35 -07:00
David Euresti
4e40b035c8 BaseException does not take keyword arguments (#2348)
Fixes #2344
2018-07-27 13:28:43 -07:00
Ville Skyttä
f5fc356928 markupbase: Fix unkown_decl typo (#2342) 2018-07-21 23:37:21 -07:00
Omar Sandoval
42db5ad4f7 Add missing int.__index__() signature (#2335)
This has been present since Python 2.5.
2018-07-16 15:30:06 -07:00
Ethan Smith
cc45366ca5 Merge 2/genericpath and 2and3/genericpath (#2330) 2018-07-13 14:07:15 -07:00
Sebastian Rittau
a38dbc6c1e Merge decimal (#2306) 2018-07-09 19:03:01 -07:00
Yusuke Miyazaki
5bb58af6c8 Use float instead of Union[int, float] (#2308) 2018-07-09 19:02:03 -07:00
Steven Karas
d4c15011e4 add __new__ to tuple in python2 (#2304)
this solves #2091 when checking Python 2 code (#2092 only fixed it for Python 3).
2018-07-03 08:18:01 -07:00
Yusuke Miyazaki
1ae2ba0fbe Use sys.platform instead of comments (#2286) 2018-07-03 08:13:04 -07:00
Yusuke Miyazaki
6192cce9d9 Avoid using string literals in type annotations (#2294) 2018-07-02 20:23:29 -07:00
Sebastian Rittau
6a18bd3ec2 Add missing self to TestCase.addCleanup() (#2301) 2018-07-02 12:12:59 -07:00
Yusuke Miyazaki
581705d9ee Prefer to use ellipsis over pass (#2292) 2018-06-28 10:29:45 -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
Philipp Hahn
ee07115c96 urllib2.build_open() accepts instances and classes (#2284)
<https://docs.python.org/2/library/urllib2.html#urllib2.build_opener>
> handlers can be either instances of BaseHandler, or subclasses of
> BaseHandler (in which case it must be possible to call the constructor
> without any parameters).
2018-06-27 20:13:46 -07:00
Michael Lee
fb92ee84c5 Make overloads in the Python 2 builtins with a 'None' fallback come first (#2261)
In short, this change makes sure calls like `map(None, a, b)` behave as
expected when using `--no-strict-optional` is enabled.

For additional context, see https://github.com/python/mypy/issues/5246
2018-06-20 08:26:06 -07: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
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
Anthony Sottile
56c93c85c0 Add NoReturn to execv* family of functions (#2226) 2018-06-15 07:55:45 -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
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
f5a74fd5da remove Optional from type of __slots__ (#2128)
Fixes #1853
2018-06-11 14:29:11 -07:00
Sebastian Rittau
a3031adb46 Merge Python 2 and 3 SSL stubs (#2175) 2018-05-31 21:44:42 -07:00
Mathieu Leduc-Hamel
351d019241 Mark inspect.getmembers as Optional for both Py2 and Py3 (#2172) 2018-05-29 10:43:34 -07:00
Sushain Cherivirala
dc0fcdcaa0 Add missing signals to Py2/3; missing events to Py2; PEP 526 refactoring (fixes #1576) (#2168) 2018-05-27 22:50:10 -07:00