Skip to content

Typing issue when using class based views [BUG] #63

@yeralin

Description

@yeralin

Describe the bug
When I tried to use @cbv(router) and added a class attribute with Depends, my pylint started complaining with E1101: Instance of 'Depends' has no '...' member (no-member).

To Reproduce

from fastapi import APIRouter, Path, Depends, Query
from fastapi_utils.cbv import cbv

router = APIRouter()

class ControllerClass:

    def get_sample() -> str:
        return "sample"

def get_controller() -> ControllerClass:
     return ControllerClass()

@cbv(router)
class MyRouter:

    controller: ControllerClass = Depends(get_controller)

    @router.get("/sample")
    async def sample(self) -> str:
        return self.controller.get_sample() # <- this line recognizes self.controller as `Depends` instance, not `ControllerClass`

# > E1101: Instance of 'Depends' has no 'get_sample' member (no-member)

Although, functionally everything works just fine.

Expected behavior
The typing of the class var should be inferred as ControllerClass, not Depends.

Environment:

  • OS: MacOS 19.5.0 Darwin Kernel Version
  • FastAPI Utils, FastAPI, and Pydantic versions:
>>> print(fastapi_utils.__version__)
0.2.1
>>> print(fastapi.__version__)
0.55.1
>>> print(pydantic.utils.version_info())
             pydantic version: 1.5.1
            pydantic compiled: True
               python version: 3.7.7 (default, May  6 2020, 04:59:01)  [Clang 4.0.1 (tags/RELEASE_401/final)]
                     platform: Darwin-19.5.0-x86_64-i386-64bit
     optional deps. installed: ['typing-extensions']
  • Python version, get it with: Python 3.7.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions