Commit Graph

73 Commits

Author SHA1 Message Date
5j9
f192b8c784 Update count, (r)find, and (r)index type hints for bytes and bytearray (#923)
The above methods have changed in version 3.3 to also accept an integer in
the range 0 to 255 as the subsequence.

Fixes python/mypy#2831
2017-02-08 15:21:41 -08:00
Andrey Vlasovskikh
bb33cb0119 Added __instancecheck__ and __subclasscheck__ to type (#887) 2017-01-29 11:17:01 -08:00
Andrey Vlasovskikh
8ce64ce782 Updates to slice built-in (#891)
Makes args and attributes optional.
2017-01-29 11:16:23 -08:00
Andrey Vlasovskikh
2b25b3ef6d Argument of input() is not restricted to str (#890) 2017-01-29 10:34:32 -08:00
Andrey Vlasovskikh
c8435f4315 Added object.__sizeof__ (#865)
* Added object.__sizeof__

* Removed __sizeof__ inherited from object

* Made sqlite3 classes for Python 2 inherit from object

* Removed __sizeof__ inherited from object
2017-01-26 12:05:53 -08:00
Andrey Vlasovskikh
025f31dcc9 Added class super to builtins (#867) 2017-01-26 11:53:59 -08:00
Alex Frieder
cf98162fca Add __bool__ to numeric builtin types 2017-01-20 12:41:16 -08:00
Jukka Lehtosalo
f2579e532f Update signature of dict.get (#852)
Without this change, mypy can't infer proper types for cases like
`d.get(k, [])` where it needs type context to infer the type of
`[]`. We add the value type to the second argument to `get` using
union types, and this provides the context. This doesn't affect
the effective signature of `get`, other than providing the type
context for mypy.

Also removed some related redundant method definitions where we can
just inherit the base class definition. This makes it easier to
keep the method signatures consistent.

Note that this requires a few mypy PRs before mypy will be able to
use this effectively:

* https://github.com/python/mypy/pull/2718
* https://github.com/python/mypy/pull/2715
2017-01-20 07:41:54 -08:00
Dylan Jenkinson
6339f88ae4 Updated the stub for builtins to change slice to take Optional[int] rather than just straight int. 2017-01-18 11:30:41 -08:00
Roy Williams
41ba734fc2 Fix return type of next when default parameter is provided.
**test_next.py**:
```python
z = (x*2 for x in range(10))
reveal_type(next(z, None))
```

Before:
```shell
test_next.py:2: error: Revealed type is 'builtins.int*'
```

After:
```shell
test_next.py:2: error: Revealed type is 'Union[builtins.int*, builtins.None]'
```
2017-01-13 09:46:51 -08:00
Roy Williams
6008b9dbb1 Overload signature of get to return an Optional value and to allow default to take any type to match runtime behavior.
This chage more closely matches the behavior of `get` at runtime.  Users can pass whatever they want in to the default
parameter and it will be returned if the key is absent.  Additionally, `get` should return an `Optional` if called with
only one parameter.

```python
z = {'a': 22}
reveal_type(z.get('b'))
reveal_type(z.get('b', 22))
reveal_type(z.get('b', 'hello'))
```

Before:
```shell
test_get_default.py:2: error: Revealed type is 'builtins.int*'
test_get_default.py:3: error: Revealed type is 'builtins.int*'
test_get_default.py:4: error: Revealed type is 'builtins.int*'
test_get_default.py:4: error: Argument 2 to "get" of "dict" has incompatible type "str"; expected "int"
```

After:
```shell
test_get_default.py:2: error: Revealed type is 'Union[builtins.int*, builtins.None]'
test_get_default.py:3: error: Revealed type is 'builtins.int'
test_get_default.py:4: error: Revealed type is 'Union[builtins.int, builtins.str*]'
```
2017-01-11 22:02:29 -08:00
Jelle Zijlstra
f9135c5aa0 add __init_subclass__ to 3.6 (#813)
See also https://github.com/python/mypy/pull/2654
2017-01-09 09:22:20 -08:00
David Fisher
2cb8e184cc Add NoReturn (#811)
* Add NoReturn
2017-01-04 13:38:05 -08:00
z33ky
93bb4604cb Add special methods for object (#774)
* Add special methods for object

* Add __format__ to 2/__builtin__.pyi too

* Remove redundant __format__ from float.
2017-01-04 13:52:51 +00:00
Lukasz Langa
6e2709906b Fixing flake8 B errors 2016-12-20 01:17:38 -08:00
Lukasz Langa
67e38b6806 Fixing flake8 E231 errors 2016-12-19 23:53:19 -08:00
Lukasz Langa
fe0e3744cc Fixing flake8 E261 errors 2016-12-19 22:09:35 -08:00
TrueBrain
7e89fc0d49 Define __slots__ for object as Iterable[str] / Iterable[Union[str, unicode]] (#780)
* Define __slots__ for object as Iterable[str] / Iterable[Union[str, unicode]]
* A string as __slots__ value is also valid and represents a single item
2016-12-19 13:09:04 -08:00
David Fisher
beb9183103 Swap order of overloads to fix filter without strict optional (#779)
Related to python/mypy#2587
2016-12-16 15:57:04 -08:00
David Fisher
957307b785 Make filter work properly with Optional elements (#775) 2016-12-15 17:53:38 -08:00
Jelle Zijlstra
97a6d27558 Make first argument to filter optional
```
$ python3.4
Python 3.4.3 (default, Nov 17 2016, 01:08:31) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> list(filter(None, [False, True]))
[True]
>>> 
```
2016-12-12 11:31:12 -08:00
Josiah Boning
c9ad4b8dc0 Have frozenset inherit from FrozenSet (#726)
Fixes python/mypy#2514
2016-11-30 17:58:11 -08:00
TrueBrain
341c4edc37 Args is a predefined attribute on BaseException, and always Tuple[Any, ...] (#666) 2016-11-05 16:33:58 -07:00
Guido van Rossum
7c20adb715 Fix memoryview stub (#651)
Fixes python/mypy#2390
2016-11-02 17:18:44 -07:00
TrueBrain
15ec66cdd6 Consider __doc__ always Optional. (#641)
python/mypy#2380 showed a discrepancy between object and FunctionType in stdlib2. The first defined __doc__ to be str, the second Optional[str]. As FunctionType depends on object, this is no longer valid.

As suggested by @gvanrossum in python/mypy#2380, all __doc__ should be considered Optional.

(Final verdict was just to remove most __doc__ attributes since it's inherited from object.)
2016-10-30 11:48:23 -07:00
Elazar Gershuni
7a623f2cea Dedicated TypeVar for type.__subclasses__ (#639) 2016-10-30 10:29:51 -07:00
Guido van Rossum
c3ddd3c5f2 Improve __subclasses__() signature. Fixes python/mypy#2236. 2016-10-27 17:31:03 -07:00
Kai Lautaportti
8fec896898 Added RecursionError to builtins for Python >= 3.5 (#620)
Closes #619.
2016-10-19 15:06:10 -07:00
Yegor Roganov
e4073e385a Improve types of staticmethod and classmethod (#609)
Fixes #318
2016-10-15 14:17:17 -07:00
Guido van Rossum
0b04c44710 Revert last two commits.
Reason: https://github.com/python/mypy/issues/328

* Revert "Make fromkeys() take an Iterable instead of a sequence. (#605)"

  This reverts commit 66e8d4a14f.

* Revert "Make dict.fromkeys() a classmethod (which it is). (#604)"

  This reverts commit 26dfcb6859.

* Add an explanation for fromkeys() being a staticmethod.
2016-10-14 21:11:10 -07:00
Guido van Rossum
66e8d4a14f Make fromkeys() take an Iterable instead of a sequence. (#605)
(This, too, came up in python/mypy#2254 -- thanks @rwbarton!)
2016-10-14 10:00:43 -07:00
Guido van Rossum
26dfcb6859 Make dict.fromkeys() a classmethod (which it is). (#604)
This came up in https://github.com/python/mypy/issues/2254.

I don't know why it was previously defined as a staticmethod, perhaps
there was an old mypy issue?
2016-10-14 09:41:26 -07:00
jgarvin
1b9266d801 Let open() take a pathlib.Path starting in 3.6 (#596) 2016-10-13 16:17:39 -07:00
Gustavo J. A. M. Carneiro
f93642b32a Add __format__ to float, fixes #560 (#561)
Fixes #560.
2016-09-21 08:17:28 -07:00
claws
bed8a60990 add hex to bytes, bytearray, memoryview (#507) 2016-08-29 09:39:35 -07:00
David Fisher
e8df136ce8 Fix incorrectly Optional builtin function args (#500)
Many builtin functions were accidentally marked as Optional because
they were given default values of None.
2016-08-25 19:07:00 -07:00
Tomasz Elendt
34175b888d Fix __setitem__(slice, ...) of various mutable sequences (#496)
Adds support of assigning iterables to slice of mutable sequences and
bytes to bytearray's slice.
2016-08-23 19:02:50 -07:00
Tomasz Elendt
9451fa922c Add start and stop arguments to Sequence.index in Py >= 3.5 (#489)
Fixes #486.
2016-08-22 14:53:48 -07:00
Daniel F Moisset
3c76029c57 Added attributes for UnicodeEncodeError (#481) 2016-08-18 05:57:16 -07:00
tonygrue-dbx
219c57a28c Add winerror to WindowsError in builtins.pyi for Python 2.7 and 3 (#470)
Adds the int type member to WindowsError stub
2016-08-15 11:41:05 -07:00
Jakub Stasiak
f3818cabbc Handle passing a tuple of types to issubclass() (#459)
It can't be just any sequence hence Tuple is used instead of previously
mentioned Sequence.
2016-08-10 12:09:16 -07:00
johnklai1
9795200acc Add optional delete argument to bytes.translate and bytearray.translate (#416) 2016-07-28 23:38:56 -07:00
Guido van Rossum
39325bf159 Mypy now supports sys.platform and sys.version_info checks (#410) 2016-07-27 13:25:29 -07:00
Guido van Rossum
df5c64e247 Add StopAsyncIteration; also add StopIteration.value. 2016-07-19 19:45:36 -07:00
Daniel F Moisset
ba349199d7 More general types for frozenset methods (#277)
Fixes #276.
2016-07-18 17:17:57 -07:00
speezepearson
534837e1ee add __{cause,context,traceback}__ to BaseException, per PEP 3134 (#369) 2016-07-13 15:26:55 -07:00
Eklavya Sharma
bca4c81b70 builtins: Remove Exception.message. (#363)
It's not present in 3.4 either, so this looks good to me.
2016-07-13 16:11:51 +01:00
Michael Lee
adc6bf5f94 Update set methods to take multiple iterables (#349)
As of Python 2.7, you can pass in multiple iterables into some set
methods like union, intersection, difference, and update. So, for
example, `new_set = a.union(b, c)`.
2016-07-07 11:52:22 -07:00
Guido van Rossum
25a45d6daf Revert "WIP: Mapping.{get,pop} can return default type (#223)"
This reverts commit d43adbe97e.

Here's a simple example of code that breaks with this PR:

from typing import Mapping, Dict, Tuple
a = {('0', '0'): 42}  # type: Mapping[Tuple[str, str], int]
b = a.get(('1', '1'), 0)

This gives an error on the last line:
error: No overload variant of "get" of "dict" matches argument types [Tuple[builtins.str, builtins.str], builtins.int]
2016-05-30 11:55:30 -07:00
Valérian Rousset
d43adbe97e WIP: Mapping.{get,pop} can return default type (#223)
* Mapping.{get,pop} can return default type

* Mapping values are covariant
2016-05-30 10:05:44 -07:00