Re: Python 2.6 / 3.0: Determining if a method is inherited

2008-10-06 Thread Pekka Laukkanen
2008/10/5 Fuzzyman [EMAIL PROTECTED]:
 I may well be being dumb (it has happened before), but I'm struggling
 to fix some code breakage with Python 2.6.

 I have some code that looks for the '__lt__' method on a class:

 if hasattr(clr, '__lt__'):

 However - in Python 2.6 object has grown a default implementation of
 '__lt__', so this test always returns True.

 class X(object): pass
 ...
 X.__lt__
 method-wrapper '__lt__' of type object at 0xa15cf0
 X.__lt__ == object.__lt__
 False

 So how do I tell if the X.__lt__ is inherited from object? I can look
 in the '__dict__' of the class - but that doesn't tell me if X
 inherits '__lt__' from a base class other than object. (Looking inside
 the method wrapper repr with a regex is not an acceptable answer...)

I don't have Python 2.6 available, but if __lt__ on it works similarly
as __str__ on Python 2.5, you might be able to achieve this either
with inspect.ismethod or by checking methods' im_class attribute
directly:

 class C(object):
... pass
...
 class D(object):
... def __str__(self):
... return ''
...
 class E(D):
... pass
...
 import inspect
 inspect.ismethod(C().__str__)
False
 inspect.ismethod(D().__str__)
True
 inspect.ismethod(E().__str__)
True

 C().__str__.im_class
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'method-wrapper' object has no attribute 'im_class'
 D().__str__.im_class
class '__main__.D'
 E().__str__.im_class
class '__main__.E'


Cheers,
.peke
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.6 / 3.0: Determining if a method is inherited

2008-10-06 Thread Pekka Laukkanen
2008/10/7 Pekka Laukkanen [EMAIL PROTECTED]:
 2008/10/5 Fuzzyman [EMAIL PROTECTED]:
 I may well be being dumb (it has happened before), but I'm struggling
 to fix some code breakage with Python 2.6.

 I have some code that looks for the '__lt__' method on a class:

 if hasattr(clr, '__lt__'):

 However - in Python 2.6 object has grown a default implementation of
 '__lt__', so this test always returns True.

 class X(object): pass
 ...
 X.__lt__
 method-wrapper '__lt__' of type object at 0xa15cf0
 X.__lt__ == object.__lt__
 False

 So how do I tell if the X.__lt__ is inherited from object? I can look
 in the '__dict__' of the class - but that doesn't tell me if X
 inherits '__lt__' from a base class other than object. (Looking inside
 the method wrapper repr with a regex is not an acceptable answer...)

 I don't have Python 2.6 available, but if __lt__ on it works similarly
 as __str__ on Python 2.5, you might be able to achieve this either
 with inspect.ismethod or by checking methods' im_class attribute
 directly:

 class C(object):
 ... pass
 ...
 class D(object):
 ... def __str__(self):
 ... return ''
 ...
 class E(D):
 ... pass
 ...
 import inspect
 inspect.ismethod(C().__str__)
 False
 inspect.ismethod(D().__str__)
 True
 inspect.ismethod(E().__str__)
 True

 C().__str__.im_class
 Traceback (most recent call last):
  File stdin, line 1, in module
 AttributeError: 'method-wrapper' object has no attribute 'im_class'
 D().__str__.im_class
 class '__main__.D'
 E().__str__.im_class
 class '__main__.E'

Ooops, didn't notice this was suggested already. One more attempt,
hopefully this is unique. =)

 C().__str__.__objclass__
type 'object'
 D().__str__.__objclass__
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'function' object has no attribute '__objclass__'
 'spam'.__str__.__objclass__
type 'str'

Someone who actually knows what __objclas__ does can probably comment
does this make any sense in your case.

Cheers,
 .peke
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is PyFIT dead and abandoned?

2008-10-06 Thread Pekka Laukkanen
2008/10/6  [EMAIL PROTECTED]:
 I was wanting to experiment with PyFIT but it seems DOA. Googling
 doesn't yield any information less than two years old. When I try to
 install 0.8a2 I get errors because setup.py references a non-existant
 file (FitFilter.py). I find it hard to believe that in two years
 nobody has stumbled over this unless there's simply no one using it.

 Has PyFIT been completely abandoned? Is there a better alternative or
 other resources to help me integrate fitnesse and python?

AFAIK PyFIT is still developed by John Roth, who's, AFAIK gain, also
the original author this FIT port. Fitnesse mailing list [1] is
probably the best place for asking further questions.

If you are interested in acceptance testing frameworks, especially
ones implemented with Python, you may also want to take a look at
Robot Framework [2]. This framework is FIT-like but original
influences come elsewhere. To get an overview of the most important
features, take a look at the Quick Start Guide [3].

I'm the lead developer of Robot Framework so I'm too biased to
objectively compare it to PyFIT or other frameworks. I'd be interested
in hearing comments and feedback from others, though, and promise to
answer questions and otherwise help getting started. I'll probably
also send a bit longer announcement mail to this list soonish
(assuming that such announcements are OK to moderators).

Cheers,
.peke

[1] http://tech.groups.yahoo.com/group/fitnesse/
[2] http://robotframework.org
[3] http://code.google.com/p/robotframework/wiki/QuickStartGuide
--
http://mail.python.org/mailman/listinfo/python-list


Re: list to tuple conversion

2008-10-01 Thread Pekka Laukkanen
2008/10/1 sc [EMAIL PROTECTED]:
 If there were a builtin function that took a list and
 returned a tuple, I'd be there, but if there is such a
 thing I need someone to point me at it.  I can't help
 thinking I am missing some obvious construct, and I'll
 be advised to go reread the tutorial, but I'm not there,
 and if you can take pity on me and point me there, I'll
 be your friend for life.  Well -- I'll be grateful...

 tuple
type 'tuple'
 tuple([1,2,3])
(1, 2, 3)
--
http://mail.python.org/mailman/listinfo/python-list


A bit weird dictionary behavior

2008-09-22 Thread Pekka Laukkanen
Hello,

just noticed this:

Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type help, copyright, credits or license for more information.
 {1: 2}
{1: 2}
 {True: False}
{True: False}
 {1: 2, True: False}
{1: False}

This must be because

 True == 1 and True in {1: 2}
True

but it still doesn't feel exactly right. Would it be worth submitting a bug?

Cheers,
.peke
--
http://mail.python.org/mailman/listinfo/python-list