Skip to content

Commit

Permalink
Fix bugs in Python2 / six removal
Browse files Browse the repository at this point in the history
  • Loading branch information
swt2c committed Feb 3, 2025
1 parent 66a9320 commit 7fa191f
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions etgtools/tweaker_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ def cleanType(self, type_name: str) -> str:
Handles translation of common C++ types to Python types, as well as a
few specific wx types to Python types.
"""
double_type = 'float' if PY3 else 'double'
long_type = 'int' if PY3 else 'long'
double_type = 'float'
long_type = 'int'
type_map = {
# Some types are guesses, marked with TODO to verify automatic
# conversion actually happens. Also, these are the type-names
Expand Down
4 changes: 2 additions & 2 deletions wx/lib/agw/aui/auibar.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(self, command_type, win_id):
:param integer `win_id`: the window identification number.
"""

if type(command_type) in int:
if isinstance(command_type, int):
wx.PyCommandEvent.__init__(self, command_type, win_id)
else:
wx.PyCommandEvent.__init__(self, command_type.GetEventType(), command_type.GetId())
Expand Down Expand Up @@ -155,7 +155,7 @@ def __init__(self, command_type=None, win_id=0):

CommandToolBarEvent.__init__(self, command_type, win_id)

if type(command_type) in int:
if isinstance(command_type, int):
self.notify = wx.NotifyEvent(command_type, win_id)
else:
self.notify = wx.NotifyEvent(command_type.GetEventType(), command_type.GetId())
Expand Down
6 changes: 3 additions & 3 deletions wx/lib/agw/aui/auibook.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def __init__(self, command_type=None, win_id=0):
:param integer `win_id`: the window identification number.
"""

if type(command_type) in int:
if isinstance(command_type, int):
wx.PyCommandEvent.__init__(self, command_type, win_id)
else:
wx.PyCommandEvent.__init__(self, command_type.GetEventType(), command_type.GetId())
Expand Down Expand Up @@ -524,7 +524,7 @@ def __init__(self, command_type=None, win_id=0):

CommandNotebookEvent.__init__(self, command_type, win_id)

if type(command_type) in int:
if isinstance(command_type, int):
self.notify = wx.NotifyEvent(command_type, win_id)
else:
self.notify = wx.NotifyEvent(command_type.GetEventType(), command_type.GetId())
Expand Down Expand Up @@ -1173,7 +1173,7 @@ def SetActivePage(self, wndOrInt):
:param `wndOrInt`: an instance of :class:`wx.Window` or an integer specifying a tab index.
"""

if type(wndOrInt) in int:
if isinstance(wndOrInt, int):

if wndOrInt >= len(self._pages):
return False
Expand Down
2 changes: 2 additions & 0 deletions wx/lib/agw/customtreectrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ def __init__(self, parent):
Latest Revision: Helio Guilherme @ 09 Aug 2018, 21.35 GMT
Version 2.7
"""

# Version Info
Expand Down
1 change: 1 addition & 0 deletions wx/lib/agw/flatmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def CreateMenu(self):
import wx
import os
import math
import io

import wx.lib.colourutils as colourutils

Expand Down
11 changes: 4 additions & 7 deletions wx/lib/agw/ultimatelistctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,6 @@ def __init__(self, parent):
IL_FIXED_SIZE = 0
IL_VARIABLE_SIZE = 1

# Python integers, to make long types to work with CreateListItem
INTEGER_TYPES = int


# ----------------------------------------------------------------------------
# Functions
Expand All @@ -567,7 +564,7 @@ def to_list(input):

if isinstance(input, list):
return input
elif isinstance(input, INTEGER_TYPES):
elif isinstance(input, int):
return [input]
else:
raise Exception("Invalid parameter passed to `to_list`: only integers and list are accepted.")
Expand Down Expand Up @@ -595,7 +592,7 @@ def CreateListItem(itemOrId, col):
:param `col`: the item column.
"""

if type(itemOrId) in INTEGER_TYPES:
if isinstance(itemOrId, int):
item = UltimateListItem()
item._itemId = itemOrId
item._col = col
Expand Down Expand Up @@ -2285,7 +2282,7 @@ def __init__(self, commandTypeOrEvent=None, winid=0):
:param `winid`: the event identifier.
"""

if type(commandTypeOrEvent) in INTEGER_TYPES:
if isinstance(commandTypeOrEvent, int):

wx.PyCommandEvent.__init__(self, commandTypeOrEvent, winid)

Expand Down Expand Up @@ -2452,7 +2449,7 @@ def __init__(self, commandTypeOrEvent=None, winid=0):

CommandListEvent.__init__(self, commandTypeOrEvent, winid)

if type(commandTypeOrEvent) in INTEGER_TYPES:
if isinstance(commandTypeOrEvent, int):
self.notify = wx.NotifyEvent(commandTypeOrEvent, winid)
else:
self.notify = wx.NotifyEvent(commandTypeOrEvent.GetEventType(), commandTypeOrEvent.GetId())
Expand Down
2 changes: 1 addition & 1 deletion wx/lib/agw/zoombar.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def __init__(self, parent, bitmap, disabledBmp=wx.NullBitmap, label=""):
self._oldHeight = 0
self._vCenter = 0
self._hCenter = 0
self._oldInc = -sys.MAXSIZE
self._oldInc = -sys.maxsize
self._isSeparator = False
self._enabled = True

Expand Down
6 changes: 3 additions & 3 deletions wx/lib/intctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#----------------------------------------------------------------------------

MAXSIZE = sys.maxsize # (constants should be in upper case)
MINSIZE = -sys.MAXSIZE-1
MINSIZE = -sys.maxsize-1
LONGTYPE = int

#----------------------------------------------------------------------------
Expand Down Expand Up @@ -697,7 +697,7 @@ def IsInBounds(self, value=None):
value = self.GetValue()

if( not (value is None and self.IsNoneAllowed())
and type(value) not in int ):
and not isinstance(value, int) ):
raise ValueError (
'IntCtrl requires integer values, passed %s'% repr(value) )

Expand Down Expand Up @@ -809,7 +809,7 @@ def _toGUI( self, value ):
elif type(value) == LONGTYPE and not self.IsLongAllowed():
raise ValueError (
'IntCtrl requires integer value, passed long' )
elif type(value) not in int:
elif not isinstance(value, int):
raise ValueError (
'IntCtrl requires integer value, passed %s'% repr(value) )

Expand Down
4 changes: 2 additions & 2 deletions wx/lib/pubsub/core/kwargs/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SenderTooManyKwargs(RuntimeError):
def __init__(self, kwargs, commonArgName):
extra = kwargs.copy()
del extra[commonArgName]
msg = 'Sender has too many kwargs (%s)' % ( extra.keys(),)
msg = 'Sender has too many kwargs (%s)' % ( list(extra.keys()),)
RuntimeError.__init__(self, msg)

class SenderWrongKwargName(RuntimeError):
Expand All @@ -60,7 +60,7 @@ def sendMessage(self, _topicName, **kwarg):
if len(kwarg) > 1:
raise self.SenderTooManyKwargs(kwarg, commonArgName)
elif len(kwarg) == 1 and commonArgName not in kwarg:
raise self.SenderWrongKwargName( kwarg.keys()[0], commonArgName)
raise self.SenderWrongKwargName( list(kwarg.keys())[0], commonArgName)

data = kwarg.get(commonArgName, None)
kwargs = { commonArgName: self.Msg( _topicName, data) }
Expand Down
4 changes: 2 additions & 2 deletions wx/lib/pubsub/core/kwargs/topicargspecimpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ def check(self, msgKwargs):
hasReqd = (needReqd <= all)
if not hasReqd:
raise SenderMissingReqdMsgDataError(
self.topicNameTuple, msgKwargs.keys(), needReqd - all)
self.topicNameTuple, list(msgKwargs.keys()), needReqd - all)

# check that all other args are among the optional spec
optional = all - needReqd
ok = (optional <= set(self.allOptional))
if not ok:
raise SenderUnknownMsgDataError( self.topicNameTuple,
msgKwargs.keys(), optional - set(self.allOptional) )
list(msgKwargs.keys()), optional - set(self.allOptional) )

def filterArgs(self, msgKwargs):
"""Returns a dict which contains only those items of msgKwargs
Expand Down
6 changes: 3 additions & 3 deletions wx/lib/pubsub/core/topicdefnprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def doneIter(self):
# remove the temporary module and its compiled version (*.pyc)
os.remove(self.__filename)
try: # py3.2+ uses special folder/filename for .pyc files
from imp import cache_from_source
from importlib.util import cache_from_source
os.remove(cache_from_source(self.__filename))
except ImportError:
os.remove(self.__filename + 'c')
Expand Down Expand Up @@ -356,7 +356,7 @@ def getDefn(self, topicNameTuple):
return desc, spec

def topicNames(self):
return self.__topicDefns.keys()
return iter(self.__topicDefns.keys())

def getTreeDoc(self):
return self.__treeDocs
Expand Down Expand Up @@ -427,7 +427,7 @@ def exportTopicTreeSpec(moduleName = None, rootTopic=None, bak='bak', moduleDoc=
if rootTopic is None:
from .. import pub
rootTopic = pub.getDefaultTopicMgr().getRootAllTopics()
elif isintance(rootTopic, str):
elif isinstance(rootTopic, str):
from .. import pub
rootTopic = pub.getDefaultTopicMgr().getTopic(rootTopic)

Expand Down
10 changes: 5 additions & 5 deletions wx/lib/pubsub/core/topicobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def getSubtopic(self, relName):

def getSubtopics(self):
"""Get a list of Topic instances that are subtopics of self."""
return self.__subTopics.values()
return list(self.__subTopics.values())

def getNumListeners(self):
"""Return number of listeners currently subscribed to topic. This is
Expand All @@ -262,12 +262,12 @@ def hasListeners(self):
def getListeners(self):
"""Get a copy of list of listeners subscribed to this topic. Safe to iterate over while listeners
get un/subscribed from this topics (such as while sending a message)."""
return self.__listeners.keys()
return list(self.__listeners.keys())

def getListenersIter(self):
"""Get an iterator over listeners subscribed to this topic. Do not use if listeners can be
un/subscribed while iterating. """
return self.__listeners.keys()
return iter(self.__listeners.keys())

def validate(self, listener):
"""Checks whether listener could be subscribed to this topic:
Expand Down Expand Up @@ -337,11 +337,11 @@ def unsubscribeAllListeners(self, filter=None):
if filter is None:
for listener in self.__listeners:
listener._unlinkFromTopic_()
unsubd = self.__listeners.keys()
unsubd = list(self.__listeners.keys())
self.__listeners = {}
else:
unsubd = []
for listener in self.__listeners.keys():
for listener in list(self.__listeners.keys()):
if filter(listener):
unsubd.append(listener)
listener._unlinkFromTopic_()
Expand Down
4 changes: 2 additions & 2 deletions wx/lib/pubsub/utils/xmltopicdefnprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def getDefn(self, topicNameTuple):
return self._topics.get(topicNameTuple, (None, None))

def topicNames(self):
return self._topics.keys()
return iter(self._topics.keys())

def getTreeDoc(self):
return self._treeDoc
Expand Down Expand Up @@ -256,7 +256,7 @@ def exportTopicTreeSpecXml(moduleName=None, rootTopic=None, bak='bak', moduleDoc
if rootTopic is None:
from .. import pub
rootTopic = pub.getDefaultTopicTreeRoot()
elif isintance(rootTopic, str):
elif isinstance(rootTopic, str):
from .. import pub
rootTopic = pub.getTopic(rootTopic)

Expand Down

0 comments on commit 7fa191f

Please sign in to comment.