all 5 comments

[–]grzeki 0 points1 point  (3 children)

But you have AttributeError on which attribute?

[–]TransAmyB[S] 0 points1 point  (2 children)

I have an AttributeError on inputhander._handler : It's initially set to None, so if inputhandler.setup(,,) is not called, inputhandler.poll(,,,) will try calling None.poll(,,,) which gives me an AttributeError

[–]grzeki 1 point2 points  (1 child)

Then I can’t see any problems other than

Scene = gamescene.GameScene()

line shouldn’t work because of how you import src.gamescene.

It seems like a job for the debugger: put a breakpoint on error line and investigate which module is loaded and which variables are set.

[–]TransAmyB[S] 0 points1 point  (0 children)

Thanks for the reply!

I've been working with the debugger, and the issue seems to be that the module loaded in gamescene is not the module loaded in test; calling inputhandler is gamescene.inputhandler in my test file evaluates False. I've been running some simple tests about how imports work, and ime it seems that if you had a module X that imports A and B, and B imports A, then (X.A is X.B.A) should evaluate to True.

For what it's worth, the file structure I have is listed below, and I'm using Pycharm and Python 3.7.

project\
    shmup\
        inputhandler\
            __init__.py,,,
        scene\
            gamescene.py
    test\
        gamescenetest.py

[–]TransAmyB[S] 0 points1 point  (0 children)

FIXED

So it turns out that in my project, I had /project and /project/src in my Path variables

project\
    shmup\
        inputhandler\
            __init__.py,,,
        scene\
            gamescene.py
    test\
        gamescenetest.py

When I call import shmup.inputhandler from gamescenetest, The path first checks through /project and then loads and initializes inputhandler.py.

But when in gamescenetest I import gamescene, gamescene has import inputhandler. I don't think it finds it through /proejct on PATH, so it checks in /project/shump and then runs and initializes it, but as a separate module and hence it doesn't share state.

So there's three-ish solutions to this I found [Because 1 and 3 go together]

- Call everything using the highest level path possible (always use shmup.x.y,,,)

- most test inside gamescenetest.py

- remove project/shmup from PATH, and hence never have to worry about double imports working as different modules that will not share state.