Skip to content

Conversation

@altendky
Copy link
Collaborator

No description provided.

@altendky altendky marked this pull request as draft September 12, 2020 23:58
@altendky
Copy link
Collaborator Author

I'm looking into the ones that take tuples of types, but if you know how to handle it...

@altendky
Copy link
Collaborator Author

This is disgusting but I don't know of a better way yet. Maybe it's worth skipping the tuple-taking overloads.

https://repl.it/@altendky/CalmSickDistributeddatabase-1

import string


upper_letters = ['T' + c for c in string.ascii_uppercase]


def create_typevars(
    names=upper_letters,
    typevar='typing.TypeVar',
    bound=None,
):
    if bound is None:
        bound_argument = ''
    else:
        bound_argument = f', bound={bound}'
    return [
        f'{name} = {typevar}("{name}"{bound_argument})'
        for name in names
    ]


def main():
    names = upper_letters[:4]
    print('\n'.join(create_typevars(names=names, bound='QObject')))

    template = 'def findChildren(self, types: typing.Tuple[{0}], name: str = ..., options: typing.Union[Qt.FindChildOptions, Qt.FindChildOption] = ...) -> typing.List[typing.Union[{0}]]: ...'

    for index in range(len(names)):
        print(template.format(', '.join(names[:index + 1])))

main()
TA = typing.TypeVar("TA", bound=QObject)
TB = typing.TypeVar("TB", bound=QObject)
TC = typing.TypeVar("TC", bound=QObject)
TD = typing.TypeVar("TD", bound=QObject)
def findChildren(self, types: typing.Tuple[TA], name: str = ..., options: typing.Union[Qt.FindChildOptions, Qt.FindChildOption] = ...) -> typing.List[typing.Union[TA]]: ...
def findChildren(self, types: typing.Tuple[TA, TB], name: str = ..., options: typing.Union[Qt.FindChildOptions, Qt.FindChildOption] = ...) -> typing.List[typing.Union[TA, TB]]: ...
def findChildren(self, types: typing.Tuple[TA, TB, TC], name: str = ..., options: typing.Union[Qt.FindChildOptions, Qt.FindChildOption] = ...) -> typing.List[typing.Union[TA, TB, TC]]: ...
def findChildren(self, types: typing.Tuple[TA, TB, TC, TD], name: str = ..., options: typing.Union[Qt.FindChildOptions, Qt.FindChildOption] = ...) -> typing.List[typing.Union[TA, TB, TC, TD]]: ...

@altendky
Copy link
Collaborator Author

altendky commented Oct 1, 2020

Kick CI

@altendky altendky closed this Oct 1, 2020
@altendky altendky reopened this Oct 1, 2020
@altendky
Copy link
Collaborator Author

altendky commented Oct 1, 2020

ah, just travis trouble
image

@altendky
Copy link
Collaborator Author

altendky commented Oct 1, 2020

Maybe I'll come back and do that fancy generated variadic generics stuff but... I think it is at least good to keep that separate regardless.

@altendky altendky marked this pull request as ready for review October 2, 2020 03:05
@altendky altendky merged commit 39c78c6 into python-qt-tools:master Oct 2, 2020
@altendky altendky deleted the patch-4 branch October 2, 2020 13:24
bluebird75 pushed a commit to bluebird75/PyQt5-stubs that referenced this pull request Aug 24, 2021
Use TypeVar to help with QObject.findChild[ren]()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants