* Update default values to `...` in `__init__` and `__new__` in `int` and `str`.
* Add `__new__` to `enum.IntEnum` to override inherited `__new__`.
* Add `type: ignore` comment to `IntEnum`
From Samuel Freilich:
In Python 2, the predicate parameter in itertools.ifilter and
itertools.ifilterfalse can be None, indicating that true or false values
should be retained (functionally equivalent to passing "bool" as the
predicate). In Python 3, filter and itertools.filterfalse have
the same behavior.
Fixespython/mypy#3247
Also reviewed some related logic:
- __mod__ was added to both bytes and bytearray with PEP 461, which went into 3.5
- str.__mod__ takes only one argument, and the signature calls it "value"
- In Python 2, bytearray doesn't have __mod__ (and typeshed correctly omits it)
Also fix signature of IO.seek, IO.truncate, IO.write, and MutableMapping.update
Fixes#1016
Note: I couldn't put typing.pyi in 2and3 because of an import cycle when adding `import sys` to 2/typing.pyi
CONTRIBUTING.md says to prefer ... Not the most impactful change but fixing
these will allow us to lint for it in the future and get a consistent style.
* Missing special attributes of class instances inherited from object
* object.__reduce__ returns a tuple
It's up to its inheritors to return either a tuple or a string.
* Added object.__sizeof__
* Removed __sizeof__ inherited from object
* Made sqlite3 classes for Python 2 inherit from object
* Removed __sizeof__ inherited from object
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
**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]'
```
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*]'
```