Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type a Callable Arg without typing the positional args before it #5017

Closed
iddan opened this issue May 10, 2018 · 7 comments
Closed

Type a Callable Arg without typing the positional args before it #5017

iddan opened this issue May 10, 2018 · 7 comments

Comments

@iddan
Copy link

iddan commented May 10, 2018

  • 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
@ilevkivskyi
Copy link
Member

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).

@iddan
Copy link
Author

iddan commented May 10, 2018

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

@ilevkivskyi
Copy link
Member

See python/typing#239 and python/typing#264 for previous discussion.

@iddan
Copy link
Author

iddan commented May 10, 2018

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

@ilevkivskyi
Copy link
Member

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

@iddan
Copy link
Author

iddan commented May 10, 2018

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.

@hauntsaninja
Copy link
Collaborator

VarArg, KwArg, etc are deprecated. PEP 612 now exists. Discussion on further features is best done at github.com/python/typing

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants