Skip to content
This repository has been archived by the owner on Jun 20, 2018. It is now read-only.

Condition rename: myapp/gargoyle.py shadows gargoyle package #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

winhamwr
Copy link

With the current setup of using a myapp/gargoyle.py file for adding custom ConditionSet objects, I'm running in to an import problem. Since the file and the package are both named gargoyle, one of them shadows the other, and in this case, from myapp/gargoyle.py "import gargoyle" actually seems to be importing myapp.gargoyle. This obviously causes problems.

I'm not sure if this is something specific to the way I have my path configured. Either way, changing the file name from gargoyle.py to gargoyle_conditions.py eliminates the issue.

…ts from gargoyle.py to gargoyle_conditions.py to avoid import problems caused by myapp/gargoyle.py masking the gargoyle package.
@dcramer
Copy link
Collaborator

dcramer commented Jun 17, 2011

I haven't decided on whether I like the idea of renaming the module yet. I'm also 5 months behind on dealing with this issue :)

Are there any objections to just requiring absolute imports?

@jakul
Copy link

jakul commented Jun 29, 2011

The following code in myapp/gargoyle.py:

from gargoyle import gargoyle
from gargoyle.conditions import ModelConditionSet
from auth.models import User

class ImpersonationConditionSet(ModelConditionSet):
    pass

gargoyle.register(ImpersonationConditionSet(User))

causes ImportError at /nexus/gargoyle/ cannot import name gargoyle

DCramer, can you indicate what my imports should be?

@dcramer
Copy link
Collaborator

dcramer commented Jun 30, 2011

Just preface your file with:

from __future__ import absolute_import

@jakul
Copy link

jakul commented Jul 4, 2011

This has worked for me

@bjinwright
Copy link

This still causes import errors when you want to import things from gargoyle proper from other modules inside this app.

Example:
#Inside models.py
from gargoyle.models import Switch #This raises an ImportError

pombredanne pushed a commit to pombredanne/gargoyle that referenced this pull request Sep 17, 2016
Fixes disqus#3.

Tested with `python -WError` added to `tox` file, no warnings popped up.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants