Skip to content

Commit

Permalink
Use __all__ and __dir__ to hide non-public API.
Browse files Browse the repository at this point in the history
Closes #324.

Note that non-public symbols are still accessible when referred to
explicitly by name. But here we use the module-level __dir__()
function to define which symbols are seen when using dir(<module-name>).
This is a Python >= 3.7 only feature, but the function is just ignored
on Python 3.6.
  • Loading branch information
grahamgower committed Jun 24, 2021
1 parent 8ec4796 commit 65a93bb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
27 changes: 27 additions & 0 deletions demes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,30 @@
dump_all,
)
from .ms import from_ms

__all__ = [
"__version__",
"Builder",
"Epoch",
"AsymmetricMigration",
"Pulse",
"Deme",
"Graph",
"Split",
"Branch",
"Merge",
"Admix",
"load_asdict",
"loads_asdict",
"load",
"loads",
"load_all",
"dump",
"dumps",
"dump_all",
"from_ms",
]


def __dir__():
return sorted(__all__)
6 changes: 6 additions & 0 deletions demes/hypothesis_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

import demes

__all__ = ["graphs"]


def __dir__():
return sorted(__all__)


def prec32(x):
"""truncate x to the nearest single-precision floating point number"""
Expand Down

0 comments on commit 65a93bb

Please sign in to comment.