Fastapi: [FEATURE] Descriptive representational strings for params

Created on 11 May 2020  路  7Comments  路  Source: tiangolo/fastapi

Is your feature request related to a problem

Kind of, recently I generated a documentation for one of my personal projects using mkdocstrings and that's how it renders params:

That's the behavior I would prefer:

The solution you would like

Implement __repr__ for all classes in fastapi.params.
I am willing to do that, but first I wanted to make sure that this is a good idea and such PR would be accepted.

Describe alternatives you've considered

A dirty hack like this:

from fastapi.params import Depends as Dep

class Depends(Dep):

    def __init__(self, dependency = None, *, use_cache=True):
        super().__init__(dependency, use_cache=True)

    def __repr__(self) -> str:
        name = getattr(self.dependency, "__name__", type(self.dependency).__name__)
        args = name
        if not self.use_cache:
            args += ", use_cache=False"
        return f"Depends({args})"

Works, but it would be nice to have it by default.

answered enhancement good first issue

Most helpful comment

Yep, there's no PR with this yet, so if @victorphoenix3 or @rkbeatss are ready, go ahead! :rocket: :nerd_face:

All 7 comments

Ah, interesting, yeah, I would accept a PR doing that and testing it :heavy_check_mark: :nerd_face:

Hey is this done already? I would like to contribute

Not done yet, you can go ahead @fabrizzioalco :nerd_face: :rocket:

I think this would be a good issue for @victorphoenix3 and @rkbeatss to work on - I don't want to "steal" it out from under @fabrizzioalco if he's already started, though.

Yep, there's no PR with this yet, so if @victorphoenix3 or @rkbeatss are ready, go ahead! :rocket: :nerd_face:

This was implemented by @rkbeatss and @victorphoenix3 in https://github.com/tiangolo/fastapi/pull/1560 :rocket:

It should be available from FastAPI version 0.57.0 :tada:

Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.

Was this page helpful?
0 / 5 - 0 ratings