To support "from six.moves.cPickle import loads", we must add a stub for
six.moves.cPickle as if it were a real submodule, even though it isn't
implemented as such. This fixespython/mypy#1550.
We don't apply this approach to six.moves.builtins on Python 2, because
it seems to confuse mypy.
We also add stubs for aliases in six.moves whose underlying modules have
been added to typeshed.
For Python 2:
- six.moves.SimpleHTTPServer (alias for SimpleHTTPServer)
For Python 3:
- six.moves.tkinter_dialog (alias for tkinter.dialog)
- six.moves.tkinter_filedialog (alias for tkinter.filedialog)
- six.moves.tkinter_commondialog (alias for tkinter.commondialog)
- six.moves.tkinter_tkfiledialog (alias for tkinter.filedialog)
In Python 3, the ndigits argument of round() defaults to None. If
ndigits is excluded or explicitly None, the result is always an int. If
ndigits is not None, the result should be the same type as the number.
$ cat test.py
from fractions import Fraction
print(type(round(0.1)))
print(type(round(0.1, None)))
print(type(round(0.1, 0)))
print(type(round(Fraction(1, 10))))
print(type(round(Fraction(1, 10), None)))
print(type(round(Fraction(1, 10), 0)))
$ python3 ./test.py
<class 'int'>
<class 'int'>
<class 'float'>
<class 'int'>
<class 'int'>
<class 'fractions.Fraction'>
Update the signatures to allow for an ndigits of None.
Currently the Python 2 stub for `IntEnum` just inherits from `Enum` without changing anything, meaning that its `value` has type `Any`. This changes it such that, if you know you have an `IntEnum` you get the more specific `int` type for the `value`. Note that this has already been done for Python 3 `IntEnum` (both in `third_party/3/enum.pyi` and `stdlib/3.4/enum.pyi`).
Fixes#1961.
I mostly just replaced all str annotations with Text, including in return types. This is
only broadly correct; diffing a str and a unicode sequence actually results in a mixed
output of str and unicode. We could also keep the return types as str if using Text
causes errors in real code. For callbacks that take str, I introduced a Union alias
because a callable taking a str would not be a compatible with a parameter of type
Callable[[Text], bool].
I also fixed the return type of difflib.restore.
add_argument's type argument was recently changed to be (approximately)
`Callable[[_Text], _T]`. Because of contravariant subtyping for functions,
this had the effect of requiring that add_argument *always*
be unicode, which is wrong.
Change it to be `Callable[[str], _T]`.
This fixes an error in Travis that seems to have been caused by python/mypy#4319.
The fix was taken from the stdlib/3.4/enum.pyi stub. Mypy no longer assumes
that classes whose metaclass is EnumMeta are subclasses of Enum, so we can't
bound the typevar on Enum.
* Add _AttributeHolder and _ActionsContainer classes to argparse.
* Add Action subclasses to argparse.
* Add _UNRECOGNIZED_ARGS_ATTR, _ensure_value, _get_action_name to argparse.
* Fill in remaining _ActionsContainer attributes.
* Fill in missing argparse.ArgumentParser attributes.
* Fill in missing argparse.HelpFormatter attributes.
* Fill in remaining missing attributes on argparse classes.
* Rename TypeVar _ActionVar to _ActionT
* Add a version check for FileType attributes
* Add '# undocumented' where appropriate
* Add more # undocumented comments
* Make arguments to _ActionsContainer.add_argument more precise.