[pypy-issue] Issue #2058: tkinter TypeError (pypy/pypy)
Kevin Ednalino
issues-reply at bitbucket.org
Fri Jun 5 01:12:21 CEST 2015
New issue 2058: tkinter TypeError
https://bitbucket.org/pypy/pypy/issue/2058/tkinter-typeerror
Kevin Ednalino:
Using pypy3 Linux 64-bit:
```
#!python
3.2.5 (b2091e973da69152b3f928bfaabd5d2347e6df46, Nov 18 2014, 20:15:54)
[PyPy 2.4.0 with GCC 4.9.2]
```
The exception:
```
#!python
Exception in Tkinter callback
Traceback (most recent call last):
File "/opt/pypy3/lib-python/3/tkinter/__init__.py", line 1455, in __call__
args = self.subst(*args)
File "/opt/pypy3/lib-python/3/tkinter/__init__.py", line 1193, in _substitute
try: e.focus = getboolean(f)
File "/opt/pypy3/lib_pypy/_tkinter/app.py", line 442, in getboolean
if '\x00' in s:
TypeError: 'str' does not support the buffer interface
```
This happens when using virtual events (through a widget's bind method).
The function where the error occurs:
```
#!python
def getboolean(self, s):
if isinstance(s, int):
return s
s = s.encode('utf-8')
if '\x00' in s:
raise TypeError
v = tkffi.new("int*")
res = tklib.Tcl_GetBoolean(self.interp, s, v)
if res == tklib.TCL_ERROR:
self.raiseTclError()
return bool(v[0])
```
The issue appears to be that *s* is a bytes object, so making *'\x00'* a bytes object fixes the issue:
```
#!python
if b'\x00' in s:
```
Or another solution would be to check before encoding.
As far as I know, there are a couple other methods in the same class that have a similar pattern and would probably raise an exception also.
More information about the pypy-issue
mailing list