Commit Graph

62 Commits

Author SHA1 Message Date
Shantanu
e857ad6ba9 zip: add some overloads for heterogeneous tuples (#3830)
Technically this is a lie, since we return a heterogeneous iterator, not
a tuple. But since we don't have a way of typing heterogeneous
iterators, this is the best we can do.

Fixes https://github.com/python/mypy/issues/8454
2020-05-03 21:02:26 -07:00
Peter Pentchev
0d7665d7b8 SyntaxError's filename and lineno may be undefined. (#3918)
The Python source (Objects/exceptions.c) explicitly checks for null
pointers before using the filename and lineno members. Some libraries,
e.g. pkg_resources, set filename and lineno to undefined values if
indeed none are appropriate.
2020-04-08 20:50:49 +02:00
Shantanu
6b4fd79808 builtins: add mod to various power functions (#3816) 2020-03-06 11:07:05 +01:00
Jelle Zijlstra
6a4044fd9b Make frozenset covariant (#3808)
The convariance was lost in #1057
2020-03-04 19:24:03 -08:00
Ran Benita
36c6f94de4 stdlib/2and3/builtins: change dict.fromkeys to classmethod (#3798)
The referenced issue in mypy is fixed.
2020-03-01 23:25:52 -08:00
Rune Tynan
e8f85d9479 Fix missing types in builtins/__builtin__ (#3705)
* Fix missing type in builtins/__builtin__

* Add return type to memoryview cast
2020-02-02 22:13:48 -08:00
Shantanu
70f0dc1491 builtins: fix bytearray.fromhex (#3691)
bytearray.fromhex is a classmethod, not a staticmethod
Mark positional-only args in the other fromhex's
2020-01-30 18:58:36 -08:00
Shantanu
9798c243c9 builtins: start can be passed by keyword to sum in 3.8 (#3692) 2020-01-30 18:56:50 -08:00
Ilaï Deutel
e7ddb21ae6 range.index() takes exactly one argument (#3668) 2020-01-27 20:19:12 -08:00
Shantanu
ed95668638 builtins.pow: improve annotation (#3647) 2020-01-24 09:20:46 +01:00
Shantanu
32563e9e1d builtins: mark positional-only args as such (#3648) 2020-01-23 15:35:45 +01:00
Shantanu
61600d6877 memoryview: add cast, obj attribute (#3598)
Fixes #3594
2020-01-09 15:57:17 -08:00
hauntsaninja
1efc1baaf7 stdtypes: update for py38 (#3580) 2020-01-06 20:57:34 -08:00
Jason
a1331accbe Update int.from_bytes to allow more than sequences (#3571)
`int.from_bytes` supports both iterables of ints and objects that define
__bytes__'.  As an example `int.from_bytes(iter([1, 0]), 'little'))`
returns 1.
2020-01-05 16:02:10 +01:00
hauntsaninja
5fdd6ad1a5 builtins.print: make sep and end Optional (#3468) (#3511)
The docs for Python 2 and Python 3 both explicitly mentions that None is a
valid value for sep and end.
https://docs.python.org/3/library/functions.html#print
2019-11-29 06:02:30 -08:00
robertschweizer
a9a4fd0d42 Add ImportError constructor arguments (#3512) 2019-11-29 06:01:30 -08:00
Michael Seifert
97ecd2b91f Change the return type of __reduce__ and __reduce_ex__ to Union[str, Tuple[Any, ...]] (#3453)
This allows subclasses to return strings (which are allowed) from these
methods without having mypy throwing an error.

Closes #3452
2019-11-10 15:48:56 +01:00
Alexander Schlarb
124111534a Add the memoryview.release method (#3405) 2019-10-25 14:29:44 +02:00
Eric N. Vander Weele
966f8d24e6 Revert __import__ function annotation to return type back to Any (#3383)
From python/mypy#7582.

This partially reverts back the change in
0ee7c3c38b to have `__import__` return
`Any` instead of `ModuleType`.
2019-10-18 00:10:41 +02:00
Sebastian Rittau
b969ead0ce Reorder memoryview.__setitem__ overloads (#3365)
Necessary for python/mypy#7717
2019-10-15 14:14:48 +02:00
Sebastian Rittau
8a7d61741d Python3.8 additions and changes (#3337)
* Add as_integer_ratio() to a few types

* Add dirs_exist_ok to copytree()

* int, float, complex accept __index__ args

Also fix complex.__init__ argument names

* Add __reversed__ to dict et al.

* Python 3.8 date(time) arithmetic fixes

* Add CodeType.replace()
2019-10-10 20:51:27 -07:00
Sebastian Rittau
07c8675ba5 Remove unused # type: ignore comments (#3325) 2019-10-09 10:27:18 -07:00
wouter bolsterlee
824e94a933 Make 2-arg iter() retrun type match passed callable's return type (#3326)
This is a continuation of #3291, which was the initial fix for #3201.

The 2-arg version of iter() turns a callable into an iterator. The
changes made in #3291 introduce an Any return type for both the
callable's return type and the iterator's type, while in reality the
return type of the function is always the same as the iterator's type.
2019-10-09 08:44:41 +02:00
sinancepel
cd418e9546 introduce __floor__ and __ceil__ for int in Python 3 (#3306) 2019-10-04 19:16:32 -07:00
Utkarsh Gupta
fa571fb224 builtins.pyi: Use two type vars (#3291)
Fixes: #3201
2019-10-04 00:15:41 +02:00
Sebastian Rittau
c32e1e2280 Enable --disallow-any-generics for stubs (#3288) 2019-10-01 05:31:34 -07:00
Eric Traut
468d13a205 Modified __add__ method in tuple class (#3252)
Modified __add__ method in tuple class to allow it to accept tuples with different generic parameter types. This allows, for example:
a = (1, )
b = a + (2.4, )
2019-09-30 12:42:40 +02:00
Guido van Rossum
b336182b69 Fix some errors with --disallow-any-generics (#3276)
See #3267. Covers all of stdlib/2and3.
2019-09-29 09:15:27 -07:00
sinancepel
01b7002a89 Introduce explicit __str__ and __repr__ for Exceptions (#3247) 2019-09-23 18:25:49 +02:00
Benjamin Peterson
3fc8aec425 Allow passing str to Python 2's bytearray.extend. (#3223) 2019-09-04 23:24:58 +02:00
Sebastian Rittau
efb4af0108 Mark some types as non-hashable (#3219)
Based on @JelleZijlstra's PR #2221.

Fixes #2148
2019-09-04 17:38:09 +02:00
Ran Benita
b2cd972b17 builtins: int.__pow__ can take a modulo argument (#3192)
See:
https://docs.python.org/3/reference/datamodel.html#object.__pow__
https://docs.python.org/3/library/functions.html#pow
2019-08-17 07:23:53 -07:00
Ran Benita
c7417e8b3f builtins,numbers: harmonize float.__round__ and Real.__round__ (#3193)
See:
https://docs.python.org/3/reference/datamodel.html#object.__round__
https://docs.python.org/3/library/functions.html#round
2019-08-17 07:23:04 -07:00
Ran Benita
c0625d3280 builtins: add __trunc__ to int and float (#3194)
See:
https://docs.python.org/3/reference/datamodel.html#object.__trunc__

It also works on Python 2.7.
2019-08-17 07:22:03 -07:00
Michael Lee
b294782183 Make most contextmanager __exit__ signatures return Optional[bool] (#3179)
This pull request is a follow-up to https://github.com/python/mypy/issues/7214.

In short, within that mypy issue, we found it would be helpful to
determine between contextmanagers that can "swallow" exceptions vs ones
that can't. This helps prevent some false positive when using flags that
analyze control flow such as `--warn-unreachable`. To do this,
Jelle proposed assuming that only contextmanagers where the `__exit__`
returns `bool` are assumed to swallow exceptions.

This unfortunately required the following typeshed changes:

1. The typing.IO, threading.Lock, and concurrent.futures.Executor
   were all modified so `__exit__` returns `Optional[None]` instead
   of None -- along with all of their subclasses.

   I believe these three types are meant to be subclassed, so I felt
   picking the more general type was correct.

2. There were also a few concrete types (e.g. see socketserver,
   subprocess, ftplib...) that I modified to return `None` -- I checked
   the source code, and these all seem to return None (and don't appear
   to be meant to be subclassable).

3. contextlib.suppress was changed to return bool. I also double-checked
   the unittest modules and modified a subset of those contextmanagers,
   leaving ones like `_AssertRaisesContext` alone.
2019-08-16 16:13:33 -07:00
Jon Dufresne
0ee7c3c38b Update __import__ function annotations (#3188)
Per the docs, globals/locals is an optional argument.
Additionally, globals/locals can be any mapping type, not only a dict.
Likewise, fromlist can be any sequence (the docs mention a tuple, not a
list).
The function returns a ModuleType, not Any.
2019-08-16 11:03:00 +02:00
Phil Jones
1dc24e1c67 Add nbytes to the memoryview definition (#3167)
`nbytes`, like `contiguous`, was added in Python 3.3.
2019-08-03 07:51:55 -07:00
Ran Benita
c8e7d98c1f Allow function.__code__ in Python 2 (#3152)
The following code works:

    >>> print(sys.version)
    2.7.16 (default, Mar 11 2019, 18:59:25)
    >>> def f(): pass
    >>> print(f.__code__)
    <code object f at 0x7f8534ecc8a0, file "<stdin>", line 1>
    >>> isinstance(f.__code__, types.CodeType)
    True

but it didn't type-check with `mypy --python-version 2.7`.
2019-07-26 07:40:22 -07:00
秋葉
e2ec5d0525 Make SyntaxError.text be optional (#3119)
Closes #3118
2019-07-15 09:11:45 +02:00
Brandt Bucher
34b47101dd Slice attributes can be of any type. (#3024) 2019-07-11 12:13:32 -07:00
Chad Dombrova
e25c0cb128 "key" argument of builtin function sorted should be optional in python 2.7 (#3086) 2019-06-22 14:09:51 -07:00
Jadiker
5447ff6bfe str and unicode format functions take objects (#3068) 2019-06-17 20:09:11 +02:00
Paul Dagnelie
d13eb937f7 Implement SupportsIndex (#2996) 2019-05-16 21:55:57 -07:00
Ivan Levkivskyi
75723e3885 Add an optional opener parameter to open() function (#2977)
Fixes #2976
2019-05-09 16:59:32 +02:00
Jelle Zijlstra
bdb1de57f5 narrow signature of __contains__ for str-like classes (#2967)
Fixes #2937
2019-05-07 10:24:28 -04:00
Jia Chen
c4b249c9a8 Use dunder parameter name in _Writer.write (#2954) 2019-05-04 22:51:39 -04:00
Brandt Bucher
1fddec3f90 Positional-only arguments for built-in functions. (#2921) 2019-04-30 11:22:25 +02:00
Benjamin Peterson
4e572ae6a3 Remove format_map from Python 2 unicode. (#2933) 2019-04-24 00:42:27 +01:00
Brandt Bucher
4230e6f313 Fix quit's argument and return types to match those of exit. (#2915)
Fixes #2912.
2019-04-12 16:57:26 +02:00
Michael J. Sullivan
0350e9fa89 Fix some issues with __round__ (#2907)
In python 3, add an overload for there being no digits argument
and make it return int.

In python 2, __round__ doesn't exist and SupportsRound doesn't exist
in the typing module. Use SupportsFloat for python 2 round().

Remove decimal's __round__ overload that takes None, since it doesn't exist
2019-04-09 11:45:10 -07:00