Commit Graph

336 Commits

Author SHA1 Message Date
Michael Lee
709b193416 Rearrange overloads to account for optional arguments (#2150)
Basically, the same thing as [my previous pull request][0], except the
fixes are now focusing on functions with overlapping argument counts.

  [0]: https://github.com/python/typeshed/pull/2138
2018-05-19 09:20:16 -07:00
Dmitry Figol
f7f00c52af socket.create_connection allows host to be None (#2136) 2018-05-17 09:45:59 -04:00
Michael Lee
97d9f2eb2c Ensures overloads are ordered from narrow to broad (#2138)
This commit reorders any overloads where the first overload was
"shadowing" the second, preventing it from ever being matched by type
checkers that work by selecting the first matching overload alternative.

For example, the first overload alternative below is strictly broader
then the second, preventing it from ever being selected:

    class Parent: pass
    class Child(Parent): pass

    @overload
    def foo(x: *int) -> Parent: ...
    @overload
    def foo(x: int, y: int) -> Child: ...

The correct thing to do is to either delete the second overload or
rearrange them to look like this:

    @overload
    def foo(x: int, y: int) -> Child: ...
    @overload
    def foo(x: *int) -> Parent: ...

Rationale: I'm currently [working on a proposal][0] that would amend
PEP 484 to (a) mandate type checkers check overloads in order and
(b) prohibit overloads where an earlier alternative completely shadows
a later one.

  [0]: https://github.com/python/typing/issues/253#issuecomment-389262904

This would prohibit overloads that look like the example below, where
the first alternative completely shadows the second.

I figured it would be a good idea to make these changes ahead of time:
if my proposal is accepted, it'd make the transition smoother. If not,
this is hopefully a relatively harmless change.

Note: I think some of these overloads could be simplified (e.g.
`reversed(...)`), but I mostly stuck with rearranging them in case I was
wrong. The only overload I actually changed was `hmac.compare_digest` --
I believe the Python 2 version actually accepts unicode.
2018-05-17 09:45:33 -04:00
Omar Sandoval
aab1b20c80 Add missing namespace argument to rlcompleter.Completer (#2105)
This argument has been around since 2.3, and it's documented in the
rlcompleter docstring (although not on python.org).
2018-05-09 22:12:02 -07:00
Sebastian Rittau
09008599ce Merge Python 2 and 3 wsgiref (#2106)
* Merge Python 2 and 3 wsgiref

* Move wsigref to 2and3
2018-05-09 16:26:03 -07:00
Andrew Svetlov
142c7488a5 Implement a stub for netrc standard module (#2098) 2018-05-06 10:25:40 +01:00
Emil Hessman
4d8010a988 Define threading.local as a proper class (#2086)
Fixes #1591
2018-04-30 08:48:12 -07:00
Jelle Zijlstra
fc9a822348 specify what type Binary is (#2057)
Fixes python/mypy#4916.
2018-04-27 14:40:33 -07:00
Jelle Zijlstra
46f0bb8b91 support unicode in Python 2 for difflib (#2055)
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.
2018-04-27 14:39:18 -07:00
Jelle Zijlstra
f60ffe47a2 add attributes to locale (#2056)
Fixes #1888.
2018-04-27 14:38:22 -07:00
Jelle Zijlstra
5554b0b19b argparse.ArgumentParser.error never returns (#2082)
And neither does `.exit`.

Fixes #2081.
2018-04-25 21:30:31 -07:00
Freek Dijkstra
55a3bad0f8 fix signature for difflib.get_close_matches (#2064)
Fixes #2063.

The second argument to difflib.get_close_matches not only accepts a List, but any Iterator.
2018-04-17 14:24:27 -07:00
Siva Chandra
035774e022 Adjust return types of shed.scheduler.run. (#2050) 2018-04-13 21:00:27 -07:00
Michael J. Sullivan
d63866bd36 Fix py2 unicode handling for ArgumentParser.add_argument's text arg (#2051)
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]`.
2018-04-12 20:45:48 -07:00
Jelle Zijlstra
37aba00fe8 fix using ZipFile as a ContextManager (#2043) 2018-04-12 12:29:22 -07:00
Jelle Zijlstra
b8b78886e3 add some Optionals to traceback.pyi (#2044)
Fixes #1974
2018-04-12 12:29:07 -07:00
Jelle Zijlstra
840f34147e add a lot more distutils.errors (#2045)
Fixes #1963.

See https://github.com/python/cpython/blob/2.7/Lib/distutils/errors.py and https://github.com/python/cpython/blob/3.7/Lib/distutils/errors.py.
2018-04-12 12:28:55 -07:00
Chris Gavin
dca53fb2bd Make the help argument of argparse.add_argument Optional. (#2046) 2018-04-11 07:20:16 -07:00
Jelle Zijlstra
db989427cb dest argument to add_argument is Optional (#2040)
argparse.py checks for None in _get_optional_kwargs.
2018-04-10 21:47:30 -07:00
rchen152
e2cfc4bf0f Add private members to argparse.pyi. (#1937)
* 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.
2018-04-10 20:56:49 -07:00
Jelle Zijlstra
f37709f9c3 Merge stubs for sqlite3 (#2026)
As promised in #2014.

There are virtually no real changes between Python 2 and 3 in this module, but the stub had accumulated some meaningless differences. I also fixed a few incorrect types.
2018-04-09 12:32:59 -07:00
Jelle Zijlstra
54ecefef04 removals in Python 3.7 (#2018)
Last part of #1965.
2018-04-06 11:11:29 -07:00
Jelle Zijlstra
0acdfd1548 more 3.7 features (#2017) 2018-04-06 11:09:45 -07:00
Jelle Zijlstra
7cfbc7d17f more 3.7 features (#2015) 2018-04-06 11:09:11 -07:00
Jelle Zijlstra
ce0656a8c7 add some more Python 3.7 features (#2014) 2018-04-06 11:08:30 -07:00
Omar Sandoval
32b4eacea1 Add missing exitmsg argument to code.interact() (#2024)
According to https://docs.python.org/3/library/code.html#code.interact,
this was added in Python 3.6.
2018-04-06 07:02:58 -07:00
Christopher Schramm
7f34bbcb88 Add pkgutil.ModuleInfo (#2010) 2018-04-04 15:15:43 -07:00
Michael J. Sullivan
df55343e60 Fix some more ctypes issues (#2009)
* Make {C,WIN,PY}FUNCTYPE's restype argument optional (for void returns)
 * Make WinError return WindowsError
 * Don't have Array explicitly inherit from Sized
   (since inheriting from classes with different metaclasses causes problems, 
    and it is a protocol anyways)
 * Have Array.__iter__ properly return an Iterator instead of an Iterable
2018-03-30 18:03:52 -07:00
Michael J. Sullivan
9b99161ca9 Make argtypes in ctypes be a Sequence instead of a Tuple (#2005)
A lot of code uses lists here.
2018-03-29 14:55:56 -07:00
dgelessus
06aee52581 Fix some issues in ctypes (fixes #1983) (#1986)
* Support additional argument types for c_void_p parameters
* Don't allow passing bytes where a writable c_void_p is expected
* Fix type of ctypes._CDataMeta.__[r]mul__
* Rename ctypes._cparam to _CArgObject to match the real type name
* Fix value type of ctypes.HRESULT
* Add stub for ctypes.wintypes
* Fix trailing whitespace in ctypes.wintypes
* Add a workaround to ctypes.Array to fix incorrect typing in some cases
* Expand multiple assignments so mypy recognizes them as type aliases
* Rename ctypes._Pointer to pointer so it can be used externally
2018-03-29 12:41:42 -07:00
Bryce Guinta
f42724444f Update math stub arguments to reflect protocol support (#2002)
Update math.factorial to reflect support for __int__ protocol.
Update other math functions to reflect support for __float__
protocol.
2018-03-29 07:59:27 -07:00
Jelle Zijlstra
43e6c3c435 add more minor 3.7 new features (#2000)
part of #1965
2018-03-28 21:28:27 -07:00
Evan Krall
4563c5a1ac ArgumentParser's add_argument returns the Action that was created. (#1881)
* ArgumentParser's add_argument returns the Action that was created.

* Make add_argument's dest parameter Optional. _ArgumentGroup's add_argument should also return the Action.
2018-03-28 19:09:22 -07:00
Sebastian Rittau
0170e6d3c7 traceback.print_exception(): Arguments optional in Python 3 (#1982) 2018-03-28 18:45:14 -07:00
Patrick Meyer
6c09e19847 Add missing attribute socket to asyncore (#1991)
* Add missing attribute socket to asyncore

* Mark asyncore.dispatcher.socket as optional and undocumented
2018-03-28 10:08:44 -07:00
Semyon Proshev
8ac7f68a86 Update return type for math.ceil in Python 2 (#1989) 2018-03-27 08:09:18 -07:00
João Santos
afeecb478b RotatingFileHandler has a terminator property (#1952)
In python3 `RotatingFileHandler` is a subclass of `BaseRotatingHandler` which is a subclass of `FileHandler` which is a subclass of `StreamHandler` which as a `terminator` property but I'm getting a `"RotatingFileHandler" has no attribute "terminator"` error on my code.
2018-03-25 08:11:01 -07:00
Jelle Zijlstra
bbbffb5f4b implement some minor 3.7 features (#1966)
References:
- https://docs.python.org/dev/library/datetime.html#datetime.datetime.fromisoformat
- https://docs.python.org/dev/library/crypt.html#crypt.mksalt
- https://docs.python.org/dev/library/contextlib.html#contextlib.AbstractAsyncContextManager
- https://docs.python.org/dev/library/calendar.html#calendar.HTMLCalendar.cssclasses
- https://docs.python.org/dev/library/binascii.html#binascii.b2a_uu

Part of #1965.
2018-03-22 08:01:09 -07:00
Josh Holland
162d884d32 Make zipfile accept Text, not str (#1826) 2018-03-17 22:33:29 -07:00
dgelessus
8009a34b90 Re-add stubs for ctypes (#1906)
* Convert type comments to variable annotations in ctypes.__init__

* Add missing List import in ctypes.__init__

* Add missing bound kwarg to _CT TypeVar in ctypes.__init__

* Fix ctypes._CData classmethod definitions

* Fix ctypes Structure/Union __getattr__ definitions

Both Structure's metaclass and Structure itself define a __getattr__.
The former returns field objects (each representing a field definition
in the Structure), while the latter can return anything (the value of
the field in a specific Structure instance).
Structure also defines a __setattr__, while Structure's metaclass
does not.

BigEndianStructure, LittleEndianStructure and Union support the same
operations as Structure does, but the semantics obviously differ.

Depending on the system endianness, exactly one of the EndianStructures
is an alias for Structure, and the other one is a special Structure
subclass. For simplicity, both EndianStructures are considered
subclasses of Structure here, even though this is technically not
always accurate.

* Fix swapped parameter types in ctypes._CData.in_dll

* Add limited support for ctypes._CData.__class__.__mul__

It's not possible to specify the correct return type for __mul__ and
__rmul__ here - see comments for explanation.

* Make ctypes._FuncPtr extend ctypes._CData

* Improve typing of ctypes.cast

* Mark class attributes with ClassVar in ctypes.__init__

* Mark ctypes._CData.from_buffer[_copy] offset arg as optional

* Remove trailing whitespace in ctypes.__init__

* Don't export ctypes.UnionT

* Add ctypes._DLL.__getitem__

* Make ctypes._DLL.__get(attr|item)__ return _FuncPtr instead of Any

* Change ctypes DLL inheritance hierarchy to match the real one better

* Add some missing attributes to ctypes.CDLL

* Rename ctypes._FuncPtr so it doesn't conflict with CDLL._FuncPtr

* Fix type of ctypes.CDLL._FuncPtr

* Merge _FuncProto into _FuncPointer

The function pointer types returned by CFUNCTYPE and friends are the
same as those encountered elsewhere, so there's no need to treat them
differently.

* Fix some leftover references to ctypes._DLL

* Simplify definition of ctypes._DLLT

* Add ctypes.LibraryLoader.__get(attr|item)__

* Use Text instead of str where appropriate in ctypes.__init__

* Make ctypes.c_char accept ints

* Make ctypes.c_[w]char_p accept None

* Remove unneeded Generic base from ctypes.py_object

* Make ctypes.cast accept _cparam

* Fix ctypes._PF being declared too late

* Remove incorrect ctypes.PyDLL.__init__ override
2018-03-16 20:17:24 -07:00
rchen152
38dc8f5a6a Switch usages of mypy_extensions.NoReturn over to typing.NoReturn. (#1942)
* Change mypy_extensions.NoReturn to typing.NoReturn everywhere.
2018-03-05 12:42:29 -08:00
Kenny Do
156927d2a2 tzinfo.tzname is optional (#1934) 2018-02-28 19:14:12 -08:00
rchen152
e1243d0103 Add missing attributes, fix some parameter types in argparse.Action. (#1907) 2018-02-28 11:20:04 -08:00
Roy Williams
a618ee30d4 Fix instantiating a xml.etree.ElementTree.Element (#1930)
The methods removed by https://github.com/python/typeshed/pull/1816
are abstract in `MutableSequence` and therefore must be specified on `Element`.
2018-02-27 14:59:11 -08:00
Sebastian Rittau
38aea73b4b Merge Python 2 and 3 versions of time.pyi (#1909)
* Use variable annotations
* Replace default values by ellipses
* Remove exceptions from function bodies
* Remove superfluous comments
* Remove superfluous newlines
* Use Optional instead of Union[..., None]
* Replace Union[int, float] by just float

* Make time.pyi (Python 2) more closely resemble the Python 3 stub

* Replace _TIME_TUPLE by TimeTuple
* Reorder imports

* time.pyi: Mark two arguments as optional, mark Unix-only function

* time.pyi (Python 2): Use TimeTuple in NamedTuple and reformat

This makes time.pyi more closely match the Python3 version.

* Merge Python 2 and 3 versions of time.pyi

* Only import SimpleNamespace on Python >= 3.3

* Remove default values from module properties

* Remove Optional from strftime() and asctime()

* accept2dyear was removed in Python 3.3

* Rename TimeTuple to _TimeTuple
2018-02-24 11:49:37 -08:00
Jason Fried
f5b3979b70 contextlib.pyi ExitStack.callback take Callable (#1908)
* contextlib.pyi ExitStack.callback take Callable

The documentation for ExitStack does not specify the return type of the callable's passed to callback.  
Saying that they always return None breaks a very common use case for ExitStack, which is to "schedule" changes to a collection 
while iterating it.  

```
with ExitStack() as stack:
    for key, value in adict.items():
        if ...:
            stack.callback(adict.pop, key)
```

I also added AsyncExitStack, using Awaitable.

* Moving to Explicit Any in Generics
2018-02-24 09:41:13 -08:00
Ethan Smith
f91c891ad4 Fix name collision in contextlib on 3.7 (#1915) 2018-02-24 09:25:47 -08:00
David Euresti
8ecb74012a Add __divmod__ to numeric types (#1900)
Helps with #1889
2018-02-18 16:59:12 -08:00
Mark Amery
0c2249fbd6 Add FileHandler properties (#1834)
Fixes #1833.
2018-02-16 17:21:30 -08:00
Ilya Kulakov
1e8b953182 Add stub for AsyncExitContext added by bpo-29302. (#1876)
* Add stub for AsyncExitContext added by bpo-29302.

* ExitStack's pop_all returns an instance of type(self).
2018-02-16 17:17:17 -08:00