Skip to content

Tuple & TypeVarTuple Default Arguments #12981

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

Closed
adam-grant-hendry opened this issue Jun 14, 2022 · 1 comment
Closed

Tuple & TypeVarTuple Default Arguments #12981

adam-grant-hendry opened this issue Jun 14, 2022 · 1 comment
Labels

Comments

@adam-grant-hendry
Copy link

adam-grant-hendry commented Jun 14, 2022

Feature

It would be nice if Tuple and TypeVarTuple supported default arguments (particularly for use with Unpack).

Pitch

As a motivating example, I work with several 3rd-party C++ libraries with python bindings (e.g. PySide6). These bindings often have methods that do not support keyword arguments (C++ doesn't support keyword arguments natively). Sometimes, they have wrappers that forward *args to the particular binding. e.g.

    @staticmethod
    def mouseMove(*args):
        qtpy.QtTest.QTest.mouseMove(*args)

has C++ signatures

void mouseMove(QWindow *window, QPoint pos = QPoint(), int delay = -1)
void mouseMove(QWidget *widget, QPoint pos = QPoint(), int delay = -1)

that has default positional arguments for pos and delay.

Currently, AFAIK, there is no way to specify default arguments to either Tuple or TypeVarTuple. Without specifying default values, @overloads would be required (which one may argue is a sensible alternative, but is tedious when having to be performed for multiple methods in a large codebase):

Argument missing for parameter "args[n]"

Syntax Idea

I'm not sure how it would be implemented, but intuitively I am trying to achieve something like

MouseMoveArgs = tuple[
    qt_api.QtWidgets.QWidget | qt_api.QtGui.QWindow,
    qt_api.QtCore.QPoint = qt_api.QtCore.QPoint(),
    int = -1,  # c int
]

that I can then unpack

class QtBot:
    @staticmethod
    def mouseMove(*args: Unpack[MouseMoveArgs]) -> None: ...
@adam-grant-hendry adam-grant-hendry changed the title TypeVarTuple Default Arguments Tuple & TypeVarTuple Default Arguments Jun 14, 2022
@AlexWaygood
Copy link
Member

I'm not sure I fully understand your proposal here, but it sounds like you're proposing a change to the spec for tuple/TypeVarTuple. Discussions like that should happen over at https://github.com/python/typing rather than the mypy issue tracker, since they affect all users of Python typing, not just mypy users.

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

No branches or pull requests

2 participants