diff --git a/guide/src/project_layout.md b/guide/src/project_layout.md index d8767fef5..d1f17fd98 100644 --- a/guide/src/project_layout.md +++ b/guide/src/project_layout.md @@ -23,7 +23,8 @@ wheel. For convenience, this file includes the following: from .my_project import * __doc__ = my_project.__doc__ -__all__ = my_project.__all__ +if hasattr(my_project, "__all__"): + __all__ = my_project.__all__ ``` such that the module functions may be called directly with: diff --git a/src/module_writer.rs b/src/module_writer.rs index db5378ff4..12297cd4a 100644 --- a/src/module_writer.rs +++ b/src/module_writer.rs @@ -656,7 +656,11 @@ pub fn write_bindings_module( writer.add_bytes( &module.join("__init__.py"), format!( - "from .{module_name} import *\n\n__doc__ = {module_name}.__doc__\n__all__ = {module_name}.__all__\n", + "from .{module_name} import *\n\ + \n\ + __doc__ = {module_name}.__doc__\n\ + if hasattr({module_name}, \"__all__\"):\n\ + __all__ = {module_name}.__all__\n", module_name = module_name ) .as_bytes(), diff --git a/src/templates/__init__.py.j2 b/src/templates/__init__.py.j2 index 17b58b0e1..a64034451 100644 --- a/src/templates/__init__.py.j2 +++ b/src/templates/__init__.py.j2 @@ -2,4 +2,5 @@ from .{{ crate_name }} import * __doc__ = {{ crate_name }}.__doc__ -__all__ = {{ crate_name }}.__all__ +if hasattr({{ crate_name }}, "__all__"): + __all__ = {{ crate_name }}.__all__