Issue53

Title zope.interface doesn't accept compiled functions
Priority bug Status resolved
Superseder Nosy List kayhayen, michaelangelo
Assigned To kayhayen Keywords wrong_execution

Created on 2013-01-09.04:49:53 by michaelangelo, last changed by kayhayen.

Messages
msg168 (view) Author: kayhayen Date: 2013-03-02.06:18:51
Thanks again, this is in the 0.4.0 release now.
msg154 (view) Author: michaelangelo Date: 2013-01-23.01:34:31
Just tested, great no issue at all. Now my twisted app runs.

Thanks for all your helps, keep up the great works.
msg153 (view) Author: kayhayen Date: 2013-01-22.22:39:52
Fixed in git, please try it out and feel free to report more issues. :-)

Yours,
Kay
msg152 (view) Author: kayhayen Date: 2013-01-22.07:32:36
Hello Michaelangelo,

don't worry, this is great stuff, I love this being found. The issue here is 
that it is using the presence of "__module__" in the frame locals to detect the 
class nature.

Nuitka stands off of updating locals for performance reasons, unless an 
exception occurs. For this case, I believe it's best to code to my class re-
formulation, or the change class frames a bit, so they have a minimal locals 
immediately.

Then it will already work. I will explore that later today. Should be feasible 
though.

Thanks for the report,
Kay
msg151 (view) Author: michaelangelo Date: 2013-01-22.04:03:03
Dear Kay,
  Sorry more tests, with failures..
With this code (taken from http://docs.zope.org/zope.interface/README.html), I
encounter the errors below

<<<< test2.py <<<<
import zope.interface

class IFoo(zope.interface.Interface):
    """Foo blah blah"""
    
    x = zope.interface.Attribute("""X blah blah""")
    
    def bar(q, r=None):
        """bar blah blah"""

class Foo:
    zope.interface.implements(IFoo)

    def __init__(self, x=None):
        self.x = x
        
    def bar(self, q, r=None):
        return q, r, self.x

    def __repr__(self):
        return "Foo(%s)" % self.x

print IFoo.implementedBy(Foo)
>>>>



Traceback (most recent call last):
  File "test2.py", line 11, in <module>
    class Foo:
  File "test2.py", line 12, in Foo
    zope.interface.implements(IFoo)
  File
"C:\Python27\lib\site-packages\zope.interface-4.0.3-py2.7-win32.egg\zope\interface\declarations.py",
line 405, in implements
    _implements("implements", interfaces, classImplements)
  File
"C:\Python27\lib\site-packages\zope.interface-4.0.3-py2.7-win32.egg\zope\interface\declarations.py",
line 367, in _implements
    raise TypeError(name+" can be used only from a class definition.")

TypeError: implements can be used only from a class definition.
msg150 (view) Author: kayhayen Date: 2013-01-20.10:47:41
Thanks for trying it out. It seems that zope.interfaces is trying to detect the 
module frame by comparing frame globals to frame locals.

So far, Nuitka only set the frame globals, but not the locals for module frames, 
but now it does. I pushed the fix into develop, where I am currently working on 
new optimizations and call re-formulations, function references. The release 
tests are still running, but I believe it is good now.

Would appreciate if you checked it out. Zope seems like a good test bed for 
compatibility. :-)

Yours,
Kay
msg149 (view) Author: michaelangelo Date: 2013-01-19.09:40:58
Just pull the develop branch, there are other issues. Thanks.

Traceback (most recent call last):
  File "test1.py", line 2, in <module>
    from zope.interface import implements
  File
"C:\Python27\lib\site-packages\zope.interface-4.0.3-py2.7-win32.egg\zope\interface\__init__.py",
line 87, in zope.interface
    moduleProvides(IInterfaceDeclaration)
  File
"C:\Python27\lib\site-packages\zope.interface-4.0.3-py2.7-win32.egg\zope\interface\declarations.py",
line 702, in moduleProvides
    raise TypeError(
TypeError: moduleProvides can only be used from a module definition.
msg148 (view) Author: kayhayen Date: 2013-01-10.08:47:53
This is let you know, that I have chosen to make 2 fixes:

a) The isinstance builtin is now optimized as many other builtins are, but the 
code used is aware of compiled function and compiled generator types and will 
say True if checked for FunctionType and GeneratorType.

b) And the builtin.isinstance is replaced with a variant that does the same 
thing.

So this ought to work for full recursive compile and for code which uses parts 
in Python bytecode calling builtin isinstance.

It's currently in git only, running the tests right now, then will make a 
prerelease.

I decided against subclassing, as it's a bit unclear, what that entitles all, 
and the solutions picked should cover anything there is to instance.

Yours,
Kay
msg147 (view) Author: kayhayen Date: 2013-01-09.08:37:36
Hello Michaelangelo,

just looking at the Zope.interface code, I have immediately identified the 
culprit. Zope is using at least here "isinstance(attr, FunctionType)" as opposed 
to "inspect.isfunction()" which would work.

I am now contemplating to patch "isinstance" builtin at run-time (should be easy 
to do) or somehow making it a true statement, by turning Nuitka's compiled 
function type into something that inherits from "FunctionType", but change 
nothing else really.

That inheritence could prove more generally useful, or it could not be possible, 
or have unwanted side effects. I am going to check it out.

Anyway, I am quite confident, that it will work. I am going to a test case like 
this one:

def f():pass

print isinstance(f,FunctionType)

That should be all to reproduce the issue. It is not windows specific in any 
way, so I removed that keyword from the issue.

Thanks for reporting it, and thanks for testing with Zope. I shall try and 
provide you with a fix in the coming days.

Yours,
Kay
msg146 (view) Author: michaelangelo Date: 2013-01-09.04:49:53
Hi,
  Try a few versions of zope.interface (win32) doesn't seem to work. Can you
help need it for twisted. Thanks.


File "test1.py", line 2, in <module>
from zope.interface import implements
File
"C:\Python27\lib\site-packages\zope.interface-3.8.0-py2.7-win32.egg\zope\interface\__init__.py",
line 56, in zope.interface_wire()
  File
"C:\Python27\lib\site-packages\zope.interface-3.8.0-py2.7-win32.egg\zope\interface\interface.py",
line 822, in _wire
from zope.interface.interfaces import IAttribute
  File
"C:\Python27\lib\site-packages\zope.interface-3.8.0-py2.7-win32.egg\zope\interface\interfaces.py",
line 23, in zope.interface.interfaces
class IElement(Interface):
  File
"C:\Python27\lib\site-packages\zope.interface-3.8.0-py2.7-win32.egg\zope\interface\interface.py",
line 496, in __init__
raise InvalidInterface("Concrete attribute, " + name)
InvalidInterface: Concrete attribute, queryTaggedValue
History
Date User Action Args
2013-03-02 06:18:51kayhayensetstatus: testing -> resolved
messages: + msg168
2013-01-23 01:34:31michaelangelosetmessages: + msg154
2013-01-22 22:39:52kayhayensetmessages: + msg153
2013-01-22 07:32:36kayhayensetmessages: + msg152
2013-01-22 04:03:03michaelangelosetmessages: + msg151
2013-01-20 10:47:41kayhayensetmessages: + msg150
2013-01-19 09:40:58michaelangelosetmessages: + msg149
2013-01-13 11:22:19kayhayensettitle: zope.interface for win32 error -> zope.interface doesn't accept compiled functions
2013-01-10 08:47:53kayhayensetstatus: in-progress -> testing
messages: + msg148
2013-01-09 08:37:37kayhayensetstatus: testing -> in-progress
assignedto: kayhayen
messages: + msg147
keyword: + wrong_execution, - windows
nosy: + kayhayen
2013-01-09 04:49:53michaelangelocreate