Skip to content
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

Set __all__ in __init__.py #176

Open
wesbarnett opened this issue Nov 22, 2019 · 0 comments
Open

Set __all__ in __init__.py #176

wesbarnett opened this issue Nov 22, 2019 · 0 comments

Comments

@wesbarnett
Copy link
Collaborator

@wesbarnett wesbarnett commented Nov 22, 2019

Summary:

Good morning! I think __all__ should be set in __init__.py

Description:

I realize the following is not usually considered good practice, but if someone imports as follows it imports everything not prefixed with an underscore:

>>>from cmdstanpy import *
>>> dir()
['CmdStanGQ', 'CmdStanMCMC', 'CmdStanMLE', 'CmdStanModel', 'CmdStanVB', 
'STANSUMMARY_STATS', 'TMPDIR', '__annotations__', '__builtins__', '__doc__', '__loader__', 
'__name__', '__package__', '__spec__', 'atexit', 'cleanup_tmpdir', 'cmdstan_args', 'cmdstan_path',
'install_cmdstan', 'model', 'set_cmdstan_path', 'set_make_env', 'shutil', 'stanfit', 'tempfile', 'utils']

To solve this either __all__ can be set explicitly to those items that the project wants exported for the "public API".

For example, it could be set as:

__all__ = ['set_cmdstan_path', 'cmdstan_path', 'set_make_env',
            'install_cmdstan', 'set_cmdstan_path', 'CmdStanMLE', 'CmdStanGQ',
            'CmdStanVB', 'CmdStanModel' ]

Alternatively it could be set to an empty list indicating the module is not designed for this type of import statement:

__all__ = []

In this case the module can still be imported as usual with:

import cmdstanpy

or one can indicate what to import explicitly:

from cmdstanpy import cmdstan_path

Here is the PEP8 reference.

Current Version:

master branch (0.6.0)

@wesbarnett wesbarnett changed the title Set `__all__` in `__init__.py` Set __all__ in __init__.py Nov 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.