The annotations, formatarg, formatvarargs, formatvarkw, formatvalue,
formatreturns, and formatannotations arguments to inspect.formatargspec
have default values, but they cannot be None.
This module is going to be used by mypy for the daemon on Windows. To that end I ran stubgen on _winapi, then read through Modules/_winapi.c to add the function types. This seems to have been added in Python 3.1, but I think it is completely fine to just leave it in stdlib/3.
* add inspect.{isasyncgenfunction,isasyncgen} (3.6)
* reorder inspect.CO_* as in Python 3.6 doc
* add inspect.CO_{COROUTINE,ITERABLE_COROUTINE} (3.5)
* add inspect.CO_ASYNC_GENERATOR (3.6)
* use variable annotations
* use version checks
* Parameter.empty is a class attribute
* Signature.empty is a class attribute
The Python 2 version was slightly outdated compared to the Python 3
version.
The Python 2 version of Headers.__delitem__() had an optional argument
_index_operation that also exists in the implementation. But considering
this is internal use only, it was missing from the Python 3 version, and
it created problems with derived classes, I decided not to add it to
the merged stub. See also pallets/werkzeug#1051.
* fix type for TestCase.assertIn
This does essentially `assert member in container`, so we want a `Container`, not an `Iterable`.
This came up in 68e9d426a8..0bbee43d60 (r192525658).
* use any for assertIn
The type signature of get_grouped_opcodes() was incorrect. Resulting in type errors when checking return values.
The usage of this function is like this:
groups = sm.get_grouped_opcodes() # groups is Iterable[List[Tuple[str, int, int, int, int]]]
for group in groups: # group is List[Tuple[str, int, int, int, int]]
for opcode in group: # opcode is Tuple[str, int, int, int, int]
* Move google protobuf from 2 to 2and3
This should generally be ok. I ran the internal consistency
tests and they seemed to pass.
* Convert str to bytes
* repr to use str in google.protobuf.internal.containers
The dict stub was referring to an instance, not the type, leading to
__call__ being considered when using as a decorator, rather than
__init__.
mock is a backport of the stdlib module and should be defined the same.
Fixes#2124.
As mentioned in the issue, the current guidelines lead to extremely long lines of many hundreds of characters, which make code hard to read and review. I think there should be some limit to line length, but it's OK for stubs to have somewhat longer lines than normal code.
For reference, there are currently 115 lines in typeshed over 200 characters; 523 over 120 characters; and 2980 over 79 characters.
We picked 130 because that's the longest line GitHub displays on a 13" laptop in a unified diff without folding. There are currently 382 lines in typeshed that are over 130 characters.
* Add OpenDirector.addheaders and replace type comments with annotations
* Use ClassVar/eliminate `= ...` and add BaseHandler.handler_order (exists in Py2 versions)
* Use typing.Text
* Add InputStream and ErrorStream WSGI protocols
* Fix return type of WSGIApplication
* Add type hints to wsgiref.validate
* Replace _Bytes by plain bytes
* Add wsgiref.util
* Add wsgiref.headers
* ErrorWrapper.writelines() takes an Iterable
* Fix start_response return type
* Make Python 2 and 3 branches resemble each other more closely
* Use typing.NoReturn
* Fix WriteWrapper.writer type
* Change return type of WriteWrapper.writer to Any
Standard implementation is:
```
def process(self, msg, kwargs):
kwargs["extra"] = self.extra
return msg, kwargs
```
so the signature is clearly `(Text, ...) -> (Text, ...)` (or `(str, ...) -> (str, ...)`, but following the other stubs here, I gather it's `Text`).
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.