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

IntCtrl fails on Python3 due to the usage of long #898

Closed
gatagat opened this Issue Jun 26, 2018 · 4 comments

Comments

Projects
None yet
3 participants
@gatagat
Copy link

gatagat commented Jun 26, 2018

Operating system: NA (OSX/Linux)
wxPython version: 4.0.2 (pip installed from pypi)
Python version: 3.6

Description
An IntCtrl raises NameError on Python 3 when it parses an unparseable string. This happens because it tries to use the Python 2 long type. The unparseable string can be input by typing -1 and then deleting the 1.

Expected behavior
I would not expect wx to distinguish between int and long, since long does not exist. I would propose to deprecate the allow_long on Python 3 unless it has some special meaning I did not get.

A quick & dirty fix would be: if not six.PY2: long = int

Minimal example:

import wx
from wx.lib.intctrl import IntCtrl

app = wx.App()
frame = wx.Frame(None)
intctrl = IntCtrl(frame, min=0, max=None)
intctrl._fromGUI('-')

Traceback

Traceback (most recent call last):
  File "/.../lib/python3.6/site-packages/wx/lib/intctrl.py", line 860, in _fromGUI
    return int( value )
ValueError: invalid literal for int() with base 10: '-'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "/.../lib/python3.6/site-packages/wx/lib/intctrl.py", line 511, in OnText
    value = self.GetValue()
  File "/.../lib/python3.6/site-packages/wx/lib/intctrl.py", line 527, in GetValue
    return self._fromGUI( wx.TextCtrl.GetValue(self) )
  File "/.../lib/python3.6/site-packages/wx/lib/intctrl.py", line 863, in _fromGUI
    return long( value )
NameError: name 'long' is not defined
@mesalu

This comment has been minimized.

Copy link
Collaborator

mesalu commented Jun 26, 2018

Looks like a variable is set to the correct type early on in the module
So a change like this in that try/except (and anywhere else that's applicable) should do:

try:
    return int(value)
except ValueError:
    if self.IsLongAllowed():  # Could add a six.PY2 check here too, in order to deprecate any `long` usage in py3
        return LONGTYPE(value)
    else:
        raise

mesalu added a commit to mesalu/Phoenix that referenced this issue Jun 27, 2018

@RobinD42

This comment has been minimized.

Copy link
Member

RobinD42 commented Jun 29, 2018

Fixed by #899

@RobinD42 RobinD42 reopened this Jun 29, 2018

@mesalu

This comment has been minimized.

Copy link
Collaborator

mesalu commented Jun 29, 2018

@RobinD42 did you click reopen and comment on accident? ;)

@RobinD42

This comment has been minimized.

Copy link
Member

RobinD42 commented Jun 29, 2018

Yep

@RobinD42 RobinD42 closed this Jun 29, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment