Message43008
This patch only works if there's a real module behind the fake one, i.e. if the imported module replaces itself if sys.modules.
To test, put the following into fake.py:
---
class FakeMod:
def __init__(self, n):
self.__name__ = n
def foo(self):
return 42
import sys
sys.modules[__name__] = FakeMod(__name__)
---
On the commandline do:
>>> import fake
>>> import sys
>>> fake
<fake.FakeMod instance at 0xb77bdea4>
>>> fake.foo()
42
[Now edit fake.py and change 42 to 43]
>>> fake2 = reload(fake)
>>> fake2
<fake.FakeMod instance at 0xb77bdaec>
>>> fake.foo()
42
>>> fake2.foo()
43
>>> sys.modules['fake'].foo()
However I'm no longer sure that the patch in this form is all that useful. |
|
| Date |
User |
Action |
Args |
| 2007-08-23 15:21:08 | admin | link | issue701743 messages |
| 2007-08-23 15:21:08 | admin | create | |
|