Mypy: Type a Callable Arg without typing the positional args before it

Created on 10 May 2018  路  6Comments  路  Source: python/mypy

  • Are you reporting a bug, or opening a feature request? feature request
  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.
O = TypeVar('O')

def decorator(method : Callable[[O, VarArg(), KwArg()], Any]) -> Callable[[VarArg(), O, KwArg()], Any]:
    def x(*args, **kwargs):
        return method(args[-1], *args[0:-1], **kwargs)
    return x
  • What is the actual behavior/output?

Required positional args may not appear after default, named or var args

  • What is the behavior/output you expect?

VarArg() or ... to represent the positional args before O

  • What are the versions of mypy and Python you are using? 0.600, Python 3.6.2
    Do you see the same issue after installing mypy from Git master? Git is the same as release
  • What are the mypy flags you are using? (For example --strict-optional): No flags
feature priority-2-low

All 6 comments

This is a known limitation, we have an existing proposal, but syntax that you propose here was not considered I think. This is relatively low priority on our roadmap, so labelling accordingly (unless it is very easy to implement as a temporary workaround).

I think it should be first decided what syntax and behaviour are expected then someone could more easily pickup and implement it

I've stumbled upon them but couldn't find what was settled. Was there an agreed syntax?

This is the problem :-) There is still not 100% on the preferred syntax.

I'm leaning towards the ... syntax. It's clear, more expressive and more correct than VarArg(). Using asterisk is expressive as well but suggesting a different idea.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Stiivi picture Stiivi  路  3Comments

ericnchen picture ericnchen  路  3Comments

PeterJCLaw picture PeterJCLaw  路  3Comments

takeda picture takeda  路  3Comments

squarewave24 picture squarewave24  路  3Comments