diff --git a/docs/guide/users/recommendations/python-code.md b/docs/guide/users/recommendations/python-code.md index eb967c77..ffb6adaf 100644 --- a/docs/guide/users/recommendations/python-code.md +++ b/docs/guide/users/recommendations/python-code.md @@ -412,3 +412,18 @@ Python's type system will let you use forward references in generic types when t ``` While Griffe will load this code without error, the `'Bar'` forward reference won't be resolved to the actual `Bar` class. As a consequence, downstream tools like documentation renderers won't be able to output a link to the `Bar` class. We therefore recommend to avoid using forward references in base classes, if possible. + +Instead, you can try to declare or import the `Bar` class earlier, or make `FooBar` generic again but with a default type: + +```python +class Foo[T]: + ... + + +class FooBar[T=Bar](Foo[T]): + ... + + +class Bar: + ... +```