Skip to content

Inherit type signature from another method #2003

Description

@rowillia

Is there a way to inherit a type signature from another method? The most common use case for this is when we've got some convenience method like requests.post

Below is a super simple version of https://github.com/kennethreitz/requests/blob/master/requests/api.py#L99 which eventually calls down into https://github.com/kennethreitz/requests/blob/master/requests/sessions.py#L397

def request(method: str, url: str, data: Optional[Dict[str, Any]]=None, headers: Optional[Dict[str, str]]=None) -> Response:
  pass

def post(url: str, **kwargs) -> Response:
  # Would like to be able to annotate that **kwargs should inherit from `request`
  return request('post', url, **kwargs)

post('http://foo.com', headers={'timeout': 32})  # Should fail.

Ideally I wouldn't have to copy and paste the type signature of request into post.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions