▲ | b33j0r 5 days ago | |
I have a question. Why do you prefix your package files with an underscore? In fact, you write all of your python like you really have something to hide ;) Like `_Todo`. Where did you get this pattern? (I’m way more curious than accusatory. Are people embracing private modules these days as a convention, and I just missed it?) | ||
▲ | deathanatos 5 days ago | parent | next [-] | |
I think _private has always been a convention in Python, though I'd say most Python is not so rigorous about it. I don't see why it couldn't be applied to modules. I honestly love when I see a package do stuff like this: it's very clear then what is public interface, and I should consider usable (without sin) and what is supposed to be an internal detail. Same with the modules: then it is very clear that the re-export of those names in __init__.py is where they're meant to be consumed, and the other modules are just for organizational purposes, not API purposes. _Todo is then a private type. Very clean. | ||
▲ | Galanwe 5 days ago | parent | prev | next [-] | |
I tend to do the same, some colleagues as well, so I guess this is some common pattern. The way I see it there are two schools: - The whitelist school: You write everything without _ prefix, then you whitelist what you want accessible with __all__. - The explicit school: You forget about all and just use _ for symbols, modules, etc. I find the latter more readable and consistent (can be applied to attributes, free functions, modules... | ||
▲ | patrickkidger 5 days ago | parent | prev | next [-] | |
Yup, you(/sibling comments) have it correct, it's to mark it as private. Not sure where I got it from, it just seems clean. I don't think I see this super frequently in the ecosystem at large, although anything I've had a hand in will tend to use this style! | ||
▲ | 5 days ago | parent | prev [-] | |
[deleted] |