-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move class definitions out of __init__.py files #52
Comments
Can you elaborate on your thinking a bit for me? 😄 But also, I don't know if you saw, but in #49 I mentioned wanting to rearrange/flatten the package structure. It might coincide nicely with this? |
Yesterday it took me some time to find |
Implements serverstf#52 and flattens the structure a bit like suggested in serverstf#49
Note: Initially I was going to add this as a comment to #56. But what I ended up writing was more speculative than I originally planned, so perhaps it makes more sense here. I see little justification for not having common code directly at the package level, in It we were to do that, this change is far more compelling. For example, from valve.source.a2s import ServerQuerier
from valve.source.master_server import MasterServerQuerier
from valve.source.util import (
Platform,
ServerType,
)
I'm seen solutions to this in which all package modules are marked as private, using the well understood leading underscore convention. Then the public API is imported into package's There can be downsides to this. Mostly to do with the original module location leaking through in stack traces and such. In summary, the package structure would become something like:
As a separate consideration, it may also make sense to move Exposing the name "A2S" to the user as part of the package structure seems bad. A2S is an implementation detail. An important one, that is worthy of discussion in the documentation. A user coming to Python-valve from no experience with this stuff is surely going to be asking themselves "what on Earth is a2s"!? Returning to the initial discussion of creating a |
For me having two import locations has never been something I questioned. Almost all packages I know have one file where an object is defined and another where it's imported for convenient access. Marking the files with an underscore is only necessary if you don't consider them a public interface. Dividing the code into new sub-packages is always possible, I don't see a reason to add The current structure is not necessarily wrong, it's just not very pythonic. Imports like |
Code in
__init__.py
is horrible to find, so I suggest we keep it to the absolute minimum. Preferably imports only, but there may be some cases where actual code is necessary. Not a PR, because I want to hear your opinions first.The text was updated successfully, but these errors were encountered: