Closed CosmicWebServices closed 8 years ago
+1
Thanks!
:D
I don't like this, it means that instead of just importing slither, users have to do from slither import slither
, which just seems weird.
or from slither import *
But that's considered bad practice. and we really shouldn't be encouraging that. What's wrong with having everything in the init.py
I just realised we can put import slither
in __init__.py
But why do we need this? And besides It's not like we have optional modules for slither.
@CosmicWebServices +1
But why do we need this? And besides It's not like we have optional modules for slither.
Python style dictates that as little operational code should go in an__init__.py
file as possible. I believe the importing of slither.py, as @Omegabyte suggested is often the practice used.
I think that @Tymewalk needs to make this decision.
OK
I'm confused here.
So users will have to use from slither import *
? Why not have a from slither import *
in __init__.py
and then use import slither
like normal? Or just keeping things the way they are?
@ethanhs Where does it say that? I've never heard that rule, nor seen it used anywhere.
no it will be the same as now
@CosmicWebServices Oh, OK. But the code doesn't look that way.
Well I made it in the format that __init__.py
should be in but I would still test it...
I might have mis-spoken. What I really mean when I say "as little operational code as possible" is to say that the __init__.py
should contain setup code.
The purpose of the init.py files is to include optional initialization code that runs as different levels of a package are encountered.
and
More often that not, it’s fine to just leave the init.py files empty. However, there are certain situations where they might include code. For example, an init.py file can be used to automatically load submodules
Also:
For a simple package, you might be tempted to throw utility methods, factories and exceptions into your init.py. Don’t. A well-formed init.py serves one very important purpose: to import from sub-modules.
One more:
init.py can be an empty file but it is often used to perform setup needed for the package(import things, load things into path, etc).
Based on these, I would recommend from . import slither
or simply import slither
and move all the code to slither.py
@ethanhs +1
@ethanhs Oh, OK. That makes more sense.
Based on that I think we should restructure init.py so users can still use import slither
, but so the code is in a separate file.
yeah that makes more sense
I'm going to close this pull request as it doesn't do this which is the eventual goal (unless you'd like to update it so it does do this, @CosmicWebServices).
u do it
@CosmicWebServices I can't since I don't have write access to your repo.
If you'd like I can close this and just make a new PR.
PR?
@CosmicWebServices Pull Request
What is in the new pull request???
@CosmicWebServices I'd rewrite the current version of Slither to work so init.py only contains an import and users can still use import slither
.
OK I will do that tommarow
@CosmicWebServices OK then.
This PR is being left open since @CosmicWebServices is working on updating it.
Updated it!
I'm going to recommend that you do from . import slither
, as that will not cause issues with namespaces getting imported twice etc.
Just an idea.
Good Idea Fixing that
Done
Tests can still use import slither
correctly, right?
I think that for this change to be accepted, all the tests must work perfectly without making any changes.
@BookOwl I agree
@CosmicWebServices, what progress have you made?
It is done
OK, @Tymewalk can look it over one more time and then we can merge.
@BookOwl @CosmicWebServices I'm cloning that repo now to test.
Used import slither
in basicTest.py.
Traceback (most recent call last):
File "slither/tests/basicTest.py", line 3, in <module>
snakey = slither.Sprite()
AttributeError: 'module' object has no attribute 'Sprite'
@Tymewalk, I think that the __init__.py
file needs to be changed to from .slither import *
Yep, that fixes it.
@CosmicWebServices, can you add that fix?
Also, the tests need to be changed back to import slither
, not from slither import *
Got it...
I just tested it and it seems to work, but you need to revert the tests' import back to import slither
Other than that, it looks great! Thanks for putting in all this work.
I forgot about the tests I will do that soon (tomorrow probably)
@CosmicWebServices, when do you think that you will finish this?
I forgot doing it now
Done sorry it took so long!
See #68
Not tested.