Issue2064

classification
Title: type() to create anonymous class not working when inheriting java classes/interfaces
Type: behaviour Severity: normal
Components: Core Versions: Jython 2.7
Milestone:
process
Status: closed Resolution: invalid
Dependencies: Superseder:
Assigned To: Nosy List: pjenvey, wchang
Priority: Keywords:

Created on 2013-06-28.15:33:48 by wchang, last changed 2013-06-28.19:22:24 by pjenvey.

Messages
msg8053 (view) Author: wchang (wchang) Date: 2013-06-28.15:33:48
I'm using type to create an anonymous class using type() on jython 2.7

e.g.

>>> c = type("test_c1",(java.io.File,),{})
>>> isinstance(c,java.io.File)
False
>>> d=type("test_i1",(java.io.FilenameFilter,),{})
>>> isinstance(d,java.io.FilenameFilter)
False
msg8054 (view) Author: wchang (wchang) Date: 2013-06-28.15:36:12
I'm using type to create an anonymous class using type() on jython 2.7

However when I do the following it doesn't work.

e.g.

>>> c = type("test_c1",(java.io.File,),{})
>>> isinstance(c,java.io.File)
False
>>> d=type("test_i1",(java.io.FilenameFilter,),{})
>>> isinstance(d,java.io.FilenameFilter)
False
msg8055 (view) Author: Philip Jenvey (pjenvey) Date: 2013-06-28.19:22:24
your isinstance calls are checking against the *type* you've created. Your type 'c' is not an instance of java.io.File. However an actual instance of 'c' is (isinstance(c(), java.io.File) would be True).

c's only a subclass of File: i.e. issubclass(c, java.io.File)
History
Date User Action Args
2013-06-28 19:22:24pjenveysetstatus: open -> closed
resolution: invalid
messages: + msg8055
nosy: + pjenvey
2013-06-28 15:36:12wchangsetmessages: + msg8054
2013-06-28 15:33:48wchangcreate