diff --git a/etgtools/tweaker_tools.py b/etgtools/tweaker_tools.py index dc4fca43..dc74b646 100644 --- a/etgtools/tweaker_tools.py +++ b/etgtools/tweaker_tools.py @@ -168,8 +168,8 @@ class FixWxPrefix(object): 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 diff --git a/unittests/test_string.py b/unittests/test_string.py index a2406ed6..12ee4b12 100644 --- a/unittests/test_string.py +++ b/unittests/test_string.py @@ -9,27 +9,27 @@ from unittests import wtc class String(unittest.TestCase): if hasattr(wx, 'testStringTypemap'): - def test_StringTypemapsPy3(self): - utf = b'\xc3\xa9l\xc3\xa9phant' # utf-8 bytes - uni = utf.decode('utf-8') # convert to unicode - iso = uni.encode('iso-8859-1') # make a string with a different encoding + def test_StringTypemapsPy3(self): + utf = b'\xc3\xa9l\xc3\xa9phant' # utf-8 bytes + uni = utf.decode('utf-8') # convert to unicode + iso = uni.encode('iso-8859-1') # make a string with a different encoding - # ascii - result = wx.testStringTypemap(b'hello') - self.assertTrue(type(result) == str) - self.assertTrue(result == 'hello') + # ascii + result = wx.testStringTypemap(b'hello') + self.assertTrue(type(result) == str) + self.assertTrue(result == 'hello') - # unicode should pass through unmodified - result = wx.testStringTypemap(uni) - self.assertTrue(result == uni) + # unicode should pass through unmodified + result = wx.testStringTypemap(uni) + self.assertTrue(result == uni) - # utf-8 is converted - result = wx.testStringTypemap(utf) - self.assertTrue(result == uni) + # utf-8 is converted + result = wx.testStringTypemap(utf) + self.assertTrue(result == uni) - # can't auto-convert this - with self.assertRaises(UnicodeDecodeError): - result = wx.testStringTypemap(iso) + # can't auto-convert this + with self.assertRaises(UnicodeDecodeError): + result = wx.testStringTypemap(iso) #--------------------------------------------------------------------------- diff --git a/wx/lib/agw/aui/auibar.py b/wx/lib/agw/aui/auibar.py index 8a59d8c7..84c80d17 100644 --- a/wx/lib/agw/aui/auibar.py +++ b/wx/lib/agw/aui/auibar.py @@ -65,7 +65,7 @@ class CommandToolBarEvent(wx.PyCommandEvent): :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()) @@ -155,7 +155,7 @@ class AuiToolBarEvent(CommandToolBarEvent): 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()) diff --git a/wx/lib/agw/aui/auibook.py b/wx/lib/agw/aui/auibook.py index 573cfd22..28f1e19b 100644 --- a/wx/lib/agw/aui/auibook.py +++ b/wx/lib/agw/aui/auibook.py @@ -391,7 +391,7 @@ class CommandNotebookEvent(wx.PyCommandEvent): :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()) @@ -524,7 +524,7 @@ class AuiNotebookEvent(CommandNotebookEvent): 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()) @@ -1173,7 +1173,7 @@ class AuiTabContainer(object): :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 diff --git a/wx/lib/agw/customtreectrl.py b/wx/lib/agw/customtreectrl.py index c48926b2..1ac41a3a 100644 --- a/wx/lib/agw/customtreectrl.py +++ b/wx/lib/agw/customtreectrl.py @@ -349,6 +349,8 @@ License And Version Latest Revision: Helio Guilherme @ 09 Aug 2018, 21.35 GMT +Version 2.7 + """ # Version Info diff --git a/wx/lib/agw/flatmenu.py b/wx/lib/agw/flatmenu.py index 9ff0e3ef..92752b44 100644 --- a/wx/lib/agw/flatmenu.py +++ b/wx/lib/agw/flatmenu.py @@ -197,6 +197,7 @@ __version__ = "1.0" import wx import os import math +import io import wx.lib.colourutils as colourutils diff --git a/wx/lib/agw/ultimatelistctrl.py b/wx/lib/agw/ultimatelistctrl.py index 1c12dd8f..91ba9b2d 100644 --- a/wx/lib/agw/ultimatelistctrl.py +++ b/wx/lib/agw/ultimatelistctrl.py @@ -548,9 +548,6 @@ if wx.Platform == "__WXMSW__": IL_FIXED_SIZE = 0 IL_VARIABLE_SIZE = 1 -# Python integers, to make long types to work with CreateListItem -INTEGER_TYPES = int - # ---------------------------------------------------------------------------- # Functions @@ -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.") @@ -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 @@ -2285,7 +2282,7 @@ class CommandListEvent(wx.PyCommandEvent): :param `winid`: the event identifier. """ - if type(commandTypeOrEvent) in INTEGER_TYPES: + if isinstance(commandTypeOrEvent, int): wx.PyCommandEvent.__init__(self, commandTypeOrEvent, winid) @@ -2452,7 +2449,7 @@ class UltimateListEvent(CommandListEvent): 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()) diff --git a/wx/lib/agw/zoombar.py b/wx/lib/agw/zoombar.py index 144d0429..1a93969e 100644 --- a/wx/lib/agw/zoombar.py +++ b/wx/lib/agw/zoombar.py @@ -373,7 +373,7 @@ class ZoomBarImage(object): self._oldHeight = 0 self._vCenter = 0 self._hCenter = 0 - self._oldInc = -sys.MAXSIZE + self._oldInc = -sys.maxsize self._isSeparator = False self._enabled = True diff --git a/wx/lib/intctrl.py b/wx/lib/intctrl.py index 5cb9123f..3d5002bc 100644 --- a/wx/lib/intctrl.py +++ b/wx/lib/intctrl.py @@ -45,7 +45,7 @@ import wx #---------------------------------------------------------------------------- MAXSIZE = sys.maxsize # (constants should be in upper case) -MINSIZE = -sys.MAXSIZE-1 +MINSIZE = -sys.maxsize-1 LONGTYPE = int #---------------------------------------------------------------------------- @@ -697,7 +697,7 @@ class IntCtrl(wx.TextCtrl): 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) ) @@ -809,7 +809,7 @@ class IntCtrl(wx.TextCtrl): 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) ) diff --git a/wx/lib/pubsub/core/kwargs/publisher.py b/wx/lib/pubsub/core/kwargs/publisher.py index bda42fc5..fbe2076f 100644 --- a/wx/lib/pubsub/core/kwargs/publisher.py +++ b/wx/lib/pubsub/core/kwargs/publisher.py @@ -42,7 +42,7 @@ class PublisherArg1Stage2(Publisher): 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): @@ -60,7 +60,7 @@ class PublisherArg1Stage2(Publisher): 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) } diff --git a/wx/lib/pubsub/core/kwargs/topicargspecimpl.py b/wx/lib/pubsub/core/kwargs/topicargspecimpl.py index ea9817f1..863baf8a 100644 --- a/wx/lib/pubsub/core/kwargs/topicargspecimpl.py +++ b/wx/lib/pubsub/core/kwargs/topicargspecimpl.py @@ -114,14 +114,14 @@ class ArgsInfo: 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 diff --git a/wx/lib/pubsub/core/topicdefnprovider.py b/wx/lib/pubsub/core/topicdefnprovider.py index 6aca10fc..b8327106 100644 --- a/wx/lib/pubsub/core/topicdefnprovider.py +++ b/wx/lib/pubsub/core/topicdefnprovider.py @@ -295,7 +295,7 @@ class TopicDefnDeserialString(ITopicDefnDeserializer): # 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') @@ -356,7 +356,7 @@ class TopicDefnProvider(ITopicDefnProvider): return desc, spec def topicNames(self): - return self.__topicDefns.keys() + return iter(self.__topicDefns.keys()) def getTreeDoc(self): return self.__treeDocs @@ -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) diff --git a/wx/lib/pubsub/core/topicobj.py b/wx/lib/pubsub/core/topicobj.py index 5cfef56f..32c3f0e5 100644 --- a/wx/lib/pubsub/core/topicobj.py +++ b/wx/lib/pubsub/core/topicobj.py @@ -242,7 +242,7 @@ class Topic(PublisherMixin): 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 @@ -262,12 +262,12 @@ class Topic(PublisherMixin): 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: @@ -337,11 +337,11 @@ class Topic(PublisherMixin): 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_() diff --git a/wx/lib/pubsub/utils/xmltopicdefnprovider.py b/wx/lib/pubsub/utils/xmltopicdefnprovider.py index bca65d16..48f49e24 100644 --- a/wx/lib/pubsub/utils/xmltopicdefnprovider.py +++ b/wx/lib/pubsub/utils/xmltopicdefnprovider.py @@ -159,7 +159,7 @@ class XmlTopicDefnProvider(ITopicDefnProvider): 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 @@ -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)