Skip to content

Conversation

@donbarbos
Copy link
Contributor

@donbarbos donbarbos commented Jan 13, 2026

@github-actions

This comment has been minimized.

@donbarbos donbarbos marked this pull request as draft January 14, 2026 08:57
@github-actions

This comment has been minimized.

@donbarbos donbarbos marked this pull request as ready for review January 14, 2026 09:37
Comment on lines 1035 to 1038
@overload
def wantobjects(self) -> int: ...
@overload
def wantobjects(self, wantobjects: int, /) -> None: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least for Python 3.12, these are bools:

Python 3.12.3 (main, Jan  8 2026, 11:30:50) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> tkinter.Tk().wantobjects()
True
Suggested change
@overload
def wantobjects(self) -> int: ...
@overload
def wantobjects(self, wantobjects: int, /) -> None: ...
@overload
def wantobjects(self) -> bool: ...
@overload
def wantobjects(self, wantobjects: bool, /) -> None: ...

Copy link
Contributor Author

@donbarbos donbarbos Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I haven't checked it yet, but I think I'll need to check all the methods in other versions. In Python 3.14 I get 1

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to just use bool. See the thoughts in e.g. #4669 and #11412.

Copy link
Contributor Author

@donbarbos donbarbos Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found that, although PyArg_ParseTuple using different formats ('|i:wantobjects' in all versoins exclude 3.12 which uses '|p:wantobjects') ​​in different versions, they can always accept int and bool. I'd prefer to return int if one is returned, like this:

    if sys.version_info >= (3, 14):
        @overload
        def wantobjects(self) -> Literal[0, 1]: ...
    else:
        @overload
        def wantobjects(self) -> bool: ...
    @overload
    def wantobjects(self, wantobjects: Literal[0, 1] | bool, /) -> None: ...

what do you think? (the number is returned only starting from 3.14)

def adderrorinfo(self, msg: str, /) -> None: ...
def call(self, command: Any, /, *args: Any) -> Any: ...
def createcommand(self, name: str, func, /): ...
def createcommand(self, name: str, func: Callable[..., object], /) -> None: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that func takes arbitrary arguments? Maybe @Akuli, our resident tkinter expert has some insights. We should at least leave a TODO comment to check this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be a callback that takes two arguments like in createfilehandler. But I decided to leave it like that for now because I wasn't sure about it.
I was only sure that it was Callable because there was a check for it in the code.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a "TODO" comment to this and the other callables?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the arguments are always passed as strings, but I might be missing something. Keyword arguments are never given, because they are not a thing in Tcl.

>>> import tkinter; r = tkinter.Tk(); r.withdraw()
''
>>> r.createcommand("foo", (lambda *args: print(args)))
>>> r.call("foo", 1, 2, 3)
('1', '2', '3')
'None'
>>> r.eval("foo 1 2 3")
('1', '2', '3')
'None'
>>> r.call("foo", [1, 2, 3])
('1 2 3',)
'None'
>>> r.eval("foo [list 1 2 3]")
('1 2 3',)
'None'

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

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.

3 participants