Skip to content

Allow adding docstrings to the classes created with create_exception! #2016

@fjarri

Description

@fjarri

At the moment the recommended way of creating custom exceptions is the create_exception! macro. Unfortunately, it does not allow a docstring to be specified (since that docstring will be attached to the macro invocation and not to the actual class it creates), which leads to several problems:

  • Rust compiler gives a missing docstring warning, which cannot be silenced by #[allow(missing_docs)] (for the same reason an actual docstring cannot be specified)
  • One cannot define a docstring for the created exception and have it picked up by introspecting tools on the Python side (like help() in REPL, or sphinx.autodoc)

I tried doing an analogue of class MyError(Exception): pass in Rust (that's really all I need), but couldn't figure out how to write a constructor.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions