This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: `a.b.my_function is not b.my_function` when `a` and `b` are both on `sys.path`
Type: behavior Stage:
Components: Versions: Python 3.1, Python 3.2, Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, benjamin.peterson, cool-RR
Priority: normal Keywords:

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:06adminsetgithub: 54081
2010-09-17 11:14:13amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg116655
2010-09-17 11:07:37cool-RRsetmessages: + msg116653
2010-09-16 12:29:52benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg116537

resolution: not a bug
2010-09-16 12:28:12cool-RRcreate