Dead code in tkinter
Open
Nobody has claimed this yet.
3.16
extension-modules
topic-tkinter
type-refactor
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
Modules/_tkinter.c always defines TCL_THREADS:
/* If Tcl is compiled for threads, we must also define TCL_THREAD. We define
it always; if Tcl is not threaded, the thread functions in
Tcl are empty. */
#define TCL_THREADS
but in two places in Modules/_tkinter.c , we check if TCL_THREADS is defined:
#ifdef TCL_THREADS
static Tcl_ThreadDataKey state_key;
typedef PyThreadState *ThreadSpecificData;
#define tcl_tstate \
(*(PyThreadState**)Tcl_GetThreadData(&state_key, sizeof(PyThreadState*)))
#else
static PyThreadState *tcl_tstate = NULL;
#endif
and
#ifndef TCL_THREADS
if (v->threaded) {
PyErr_SetString(PyExc_RuntimeError,
"Tcl is threaded but _tkinter is not");
Py_DECREF(v);
return 0;
}
#endif
Especially the latter is confusing, as this code block is not compiled and the test is never executed.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
- gh-141241
- gh-152841
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in Modules/_tkinter.c by reading the TCL_THREADS definition and the two conditional blocks shown in the report, then review linked PRs gh-141241 and gh-152841 for existing work. Done means the unreachable conditional code is removed or clarified consistently without leaving the reported dead paths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- desktop
- Issue type
- Refactor
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100