Replace StartResponse arguments with ...#2379
Merged
JelleZijlstra merged 3 commits intopython:masterfrom Aug 15, 2018
Merged
Conversation
StartResponse callbacks are required to accept and optional third argument. Currently, there is no good way to describe this using type hints. Previously, a Union was used, but that causes mypy to complain about any call of start_response().
|
Hello, I have the same problem, today. In typeshed, cannot use mypy_extensions.VarArg(policy, maybe...), so cannot define the StartResponse type, that the type the function has default arguments. Why don't you use Protocol, like this? class StartResponse(Protocol):
def __call__(
self,
status: str,
headers: List[Tuple[str, str]],
exc_info: Optional[Any] = None,
) -> Callable[[bytes], None]:
...or class StartResponse(Protocol):
def __call__(
self,
status: str,
headers: List[Tuple[str, str]],
**extra: Any,
) -> Callable[[bytes], None]:
... |
Member
|
That's a good idea! I haven't tried it though. |
Collaborator
Author
|
That's an interesting idea, indeed. Unfortunately, passing in a function where a protocol is expected does not work with mypy 0.620: from typing import Protocol
class Caller(Protocol):
def __call__(self) -> None: ...
def call() -> None:
pass
def func(caller: Caller) -> None:
pass
func(call)Although maybe it should? After all, |
JelleZijlstra
approved these changes
Aug 15, 2018
yedpodtrzitko
pushed a commit
to yedpodtrzitko/typeshed
that referenced
this pull request
Jan 23, 2019
StartResponse callbacks are required to accept and optional third argument. Currently, there is no good way to describe this using type hints. Previously, a Union was used, but that causes mypy to complain about any call of start_response().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
StartResponse callbacks are required to accept and optional third argument.
Currently, there is no good way to describe this using type hints.
Previously, a Union was used, but that causes mypy to complain about any call
of start_response().