fastapi: Missing autocompletion for request.app

Describe the bug When I am using the request instance in an endpoint, my IDE does not provide me with autocompletion for request.app.

Is it maybe due to missing type hints? Or because the request instance is from Starlette and cannot be annotated in FastAPI?

To Reproduce Steps to reproduce the behavior:

  1. Create a file with
from fastapi import FastAPI
from starlette.requests import Request

app = FastAPI()

@app.get('/')
def get(request: Request):
    request.app
  1. Try to run autocompletion for request.app

Expected behavior I can use the auto-completion provided by me IDE (e.g. PyCharm)

Screenshots n/a

Environment:

  • OS: macOS

  • FastAPI Version: 0.42

  • Python version: 3.7.4

Additional context

Screenshot 2019-10-21 09 07 57

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 17 (5 by maintainers)

Most upvoted comments

I had two use cases for accessing fields of the app instance in a path operation

  1. Redirecting based user agent
if any(browser in user_agent for browser in BROWSERS):
            return RedirectResponse(url=request.app.docs_url)
        return RedirectResponse(url=request.app.openapi_url)

This would be solved by your suggestion to extract these values into a settings object.

  1. Include app version into a path endpoint

I guess your same suggestion would apply here.

I am fine with that and I missed the proposed options when creating the issue.