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
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.
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]`.
* 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.
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.
* 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
* 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
* 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.
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.
* 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
* 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
* 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