WIT runtime bug

To change the line 117 to "if otype is dict:" is not quite correct. Correct is "if isinstance(otype, dict):", because type checking has to be done by using the isinstance() built-in method. :wink:

I'll try to come up with a patch. Stay tuned. :)ile "C:\Program Files\Python 3.3.2\lib\site-packages\wx\py\filling.py",

···

line 108, in objHasChildren
    if self.objGetChildren(obj):
  File "C:\Program Files\Python 3.3.2\lib\site-packages\wx\py\filling.py",
line 117, in objGetChildren
    if otype is types.DictType \
AttributeError: 'module' object has no attribute 'DictType'

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Boštjan,

I was using the faster correction that worked (I think lib2to3 also uses this translation) .
Now I realize it is not the recommended, correct one.
Thanks

Joaquin

···

On Sunday, May 26, 2013 7:37:50 AM UTC+2, Boštjan Mejak wrote:

To change the line 117 to “if otype is dict:” is not quite correct. Correct is “if isinstance(otype, dict):”, because type checking has to be done by using the isinstance() built-in method. :wink:

I’ll try to come up with a patch. Stay tuned. :)ile “C:\Program Files\Python 3.3.2\lib\site-packages\wx\py\filling.py”,

line 108, in objHasChildren

if self.objGetChildren(obj):

File “C:\Program Files\Python 3.3.2\lib\site-packages\wx\py\filling.py”,
line 117, in objGetChildren

if otype is types.DictType \

AttributeError: ‘module’ object has no attribute ‘DictType’


You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Okay, so this is my first attempt to make WIT Python 3 compatible. However, it breaks Python 2 compatibility, but that’s something I need to dig into once I get a thumbs up from you guys.

Any comments on my patch are welcome.

filling.patch (2.46 KB)

Bo�tjan Mejak wrote:

Okay, so this is my first attempt to make WIT Python 3 compatible.
However, it breaks Python 2 compatibility, but that's something I need
to dig into once I get a thumbs up from you guys.

Any comments on my patch are welcome.

The changes like this one are not correct:

@@ -114,11 +114,11 @@ class FillingTree(wx.TreeCtrl):
          """Return dictionary with attributes or contents of object."""
          busy = wx.BusyCursor()
          otype = type(obj)
- if otype is types.DictType \
+ if isinstance(otype, dict) \
          or str(otype)[17:23] == 'BTrees' and hasattr(obj, 'keys'):
              return obj
          d = {}
- if otype is types.ListType or otype is types.TupleType:
+ if isinstance(otype, list) or isinstance(otype, tuple):
              for n in range(len(obj)):
                  key = '[' + str(n) + ']'
                  d[key] = obj[n]

otype is a type object, not something that can be an instance of a dictionary. You should check isinstance(obj, dict) instead.

On Python 2 compatibility, it only needs to stay compatible with Python 2.7, so feel free to use any compatibility helps or __future__'s that will help to write code that is compatible with both. See the ProjectPhoenix/LibraryMigration - wxPyWiki page in the wiki for more info.

···

--
Robin Dunn
Software Craftsman

So are you saying that in my patch “if otype is types.DictType:” should be “if isinstance(obj, dict):”?

Okay, here’s my new patch. Please review and comment. :wink:

filling.patch (3.51 KB)

Bo�tjan Mejak wrote:

Okay, here's my new patch. Please review and comment. :wink:

For changes like this one:

- if otype is types.StringType or otype is types.UnicodeType:
+ if isinstance(obj, str):

You should use the string_types value in wx.lib.six in order maintain compatibility with both Python 2.7 and Python 3.

from wx.lib import six
...

         if isinstance(obj, six.string_types):
             ...

Please review that module to learn about more ways to make it easier to maintain compatibility with both Pythons.

···

--
Robin Dunn
Software Craftsman

New patch. Again, please review and comment. :wink:

filling.patch (3.91 KB)

Bo�tjan Mejak wrote:

New patch. Again, please review and comment. :wink:

In this change:

- if otype is types.StringType or otype is types.UnicodeType:
+ if isinstance(obj, six.string_types) or isinstance(obj, six.text_type):

I think checking just isinstance(obj, six.string_types) is sufficient.

Also, the "Tags: py3-port" at the top should be in a comment. Did you not try running it before making the patch?

···

--
Robin Dunn
Software Craftsman

Fixed my patch according to your suggestions.

I have a question about line 145

keys.sort(lambda x, y: cmp(str(x).lower(), str(y).lower()))

which uses the cmp() function which is gone in Python 3.

How should I deal with it?

filling.patch (3.88 KB)

···

On Mon, May 27, 2013 at 10:12 PM, Robin Dunn robin@alldunn.com wrote:

Boštjan Mejak wrote:

New patch. Again, please review and comment. :wink:

In this change:

  •    if otype is types.StringType or otype is types.UnicodeType:
    
  •    if isinstance(obj, six.string_types) or isinstance(obj, six.text_type):
    

I think checking just isinstance(obj, six.string_types) is sufficient.

Also, the “Tags: py3-port” at the top should be in a comment. Did you not try running it before making the patch?

Robin Dunn

Software Craftsman

http://wxPython.org

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

maybe:

keys.sort(key=lambda x: str(x).lower())

J

···

On Monday, May 27, 2013 10:33:25 PM UTC+2, Boštjan Mejak wrote:

Fixed my patch according to your suggestions.

I have a question about line 145

keys.sort(lambda x, y: cmp(str(x).lower(), str(y).lower()))

which uses the cmp() function which is gone in Python 3.

How should I deal with it?

On Mon, May 27, 2013 at 10:12 PM, Robin Dunn ro...@alldunn.com wrote:

Boštjan Mejak wrote:

New patch. Again, please review and comment. :wink:

In this change:

  •    if otype is types.StringType or otype is types.UnicodeType:
    
  •    if isinstance(obj, six.string_types) or isinstance(obj, six.text_type):
    

I think checking just isinstance(obj, six.string_types) is sufficient.

Also, the “Tags: py3-port” at the top should be in a comment. Did you not try running it before making the patch?

Robin Dunn

Software Craftsman

http://wxPython.org

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

maybe:

keys.sort(key=lambda x: str(x).lower())

but this is not compatible with pythont 2.

In porting to python 3 Regebro recommends to use a helper function:

def cmp(a, b):
    return (a > b) - (a < b)

J
···

On Monday, May 27, 2013 10:33:25 PM UTC+2, Boštjan Mejak wrote:

Fixed my patch according to your suggestions.

I have a question about line 145

keys.sort(lambda x, y: cmp(str(x).lower(), str(y).lower()))

which uses the cmp() function which is gone in Python 3.

How should I deal with it?

On Mon, May 27, 2013 at 10:12 PM, Robin Dunn ro...@alldunn.com wrote:

Boštjan Mejak wrote:

New patch. Again, please review and comment. :wink:

In this change:

  •    if otype is types.StringType or otype is types.UnicodeType:
    
  •    if isinstance(obj, six.string_types) or isinstance(obj, six.text_type):
    

I think checking just isinstance(obj, six.string_types) is sufficient.

Also, the “Tags: py3-port” at the top should be in a comment. Did you not try running it before making the patch?

Robin Dunn

Software Craftsman

http://wxPython.org

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Fixed my patch according to your suggestions.

I have a question about line 145
keys.sort(lambda x, y: cmp(str(x).lower(), str(y).lower()))
which uses the cmp() function which is gone in Python 3.

How should I deal with it?

Boštjan Mejak wrote:

New patch. Again, please review and comment. :wink:

In this change:

- if otype is types.StringType or otype is types.UnicodeType:
+ if isinstance(obj, six.string_types) or isinstance(obj, six.text_type):

I think checking just isinstance(obj, six.string_types) is sufficient.

Also, the "Tags: py3-port" at the top should be in a comment. Did you not try running it before making the patch?

--
Robin Dunn
Software Craftsman
http://wxPython.org

--

--

maybe:
keys.sort(key=lambda x: str(x).lower())
but this is not compatible with pythont 2.
In porting to python 3 Regebro recommends to use a helper function:
def cmp(a, b):
    return (a > b) - (a < b)

J

Hi,
I don't know the context of the relevant source code, but the "key"
argument for sorting functions is perfectly valid in py 2.7;
cf.:

Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit
(Intel)] on win32
...

keys = ["a","D","A","b"]
keys.sort(); keys

['A', 'D', 'a', 'b']

keys.sort(key=lambda x: x.lower()); keys

['A', 'a', 'b', 'D']

if the str(...) call is needed, probably an appropriate alias from the
"six" module could be used (probably six.text_type).

hth,
  vbr

···

On Monday, May 27, 2013 10:33:25 PM UTC+2, Boštjan Mejak wrote:

On Mon, May 27, 2013 at 10:12 PM, Robin Dunn <ro...@alldunn.com> wrote:

2013/5/27 Joaquin Abian <gatoygata2@gmail.com>