Issue 9872: a.b.my_function is not b.my_function when a and b are both on sys.path (original) (raw)

Created on 2010-09-16 12:28 by cool-RR, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg116536 - (view) Author: Ram Rachum (cool-RR) * Date: 2010-09-16 12:28
Let's say you have this structure: a\ __init__.py b\ __init__.py In `b.__init__` a function called `my_function` is defined. And assume that `a` and `b` are both on `sys.path`. Then this situation happens: >>> import a.b >>> import b >>> a.b.my_function is b.my_function False >>> a.b.my_function <function my_function at 0x00BC70C0> >>> b.my_function <function my_function at 0x00BC7108> >>> a.b.my_function.__module__ 'a.b' >>> b.my_function.__module__ 'b' It seems that `a.b.my_function` and `b.my_function` are different objects.
msg116537 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-09-16 12:29
And indeed that's expected. Don't do that.
msg116653 - (view) Author: Ram Rachum (cool-RR) * Date: 2010-09-17 11:07
Benjamin, This behavior is involved in a problem I have with Django. When using Django, you have apps that live inside a project: my_project\ __init__.py my_app\ __init__.py views.py So if you have a view function in `views.py`, it will have two separate identities, and that causes problems. Do you have an idea what I can do about it?
msg116655 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-09-17 11:14
I suggest to report this to the Django team.
History
Date User Action Args
2022-04-11 14:57:06 admin set github: 54081
2010-09-17 11:14:13 amaury.forgeotdarc set nosy: + amaury.forgeotdarcmessages: +
2010-09-17 11:07:37 cool-RR set messages: +
2010-09-16 12:29:52 benjamin.peterson set status: open -> closednosy: + benjamin.petersonmessages: + resolution: not a bug
2010-09-16 12:28:12 cool-RR create