From: <bc...@wo...> - 2000-12-21 14:10:52
|
On Thu, 21 Dec 2000 03:15:56 +0100, you wrote: >What follows as attachment is a proposal for a patch that encompasses three >points: >* Solves [Bug #12624] and more generally separates (partially) the import >logic from __findattr__ >for py modules, this will make import more compliant with CPython but keeps >attribute-getting forced >import working (jython idiom). >* Makes __import__ hook effective also for the latter case of import through >attribute getting > (from py packages). >* Makes PyJavaPackage __mgr__ accessible and mutable from jython too. >More appropriate (than __import__) "expert" hook for java pkgs/classes std >import. > >Patch design: >* A protected method PyObject impAttr(String name) is added to PyObject. >Default impl just >calls __findattr__(name). (Better name proposals are welcome). >* Import logic in org.python.core.imp using __findattr__ is modified and >calls >impAttr instead. >* In PyModule: > * (Forced) import logic in __findattr__ is moved to an impAttr impl. > * In the case an attribute attr is not there __findattr__ try to import it >trough > __builtin__.__import__. This makes __import__ hook effective for >attribute > -getting import. > >I will check this in eventually, but only after feedback. The patch is fine, but in the situation where there if a name conmflict, is looks as if CPython will change the definition of a name in a module: Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. >>> import pack1 >>> print pack1.Node, type(pack1.Node) pack1.Node <type 'class'> >>> from pack1.Node import Node >>> print pack1.Node, type(pack1.Node) <module 'pack1.Node' from 'pack1\Node.pyc'> <type 'module'> Jython 2.0alpha2 on java1.3.0 (JIT: null) >>> import pack1 >>> print pack1.Node, type(pack1.Node) pack1.Node org.python.core.PyClass >>> from pack1.Node import Node >>> print pack1.Node, type(pack1.Node) pack1.Node org.python.core.PyClass >>> |