Instead of a docstring-only solution, wouldn’t it be better to have a more general solution to attach arbitrary attributes (potentially more than one) to any language element?
Ideally, the mechanism would be the same for variables, functions, function arguments etc.
- Rust provides such a mechanism, Attributes - The Rust Reference, with a unified syntax.
- C++11 has a similar mechanism: Attribute specifier sequence (since C++11) - cppreference.com
- C# has attributes, too: Attributes - C# language specification | Microsoft Learn
These attributes could then be used by an external typechecker to implement e.g. refinement types, as recently discussed here Would it make sense for Julia to adopt refinement types?.