fastapi-jwt icon indicating copy to clipboard operation
fastapi-jwt copied to clipboard

Problem: Expression of type "HTTPAuthorizationCredentials | None" cannot be assigned to declared type "HTTPAuthorizationCredentials"

Open TorstenD69 opened this issue 4 years ago • 1 comments

I used the article on testdriven.io to implement authorization in my project. After typing my code, I received the error above when I call the __call__method of the HTTPBearer class in my subclass (super(.....).__call__(request)). To check, if this is my fault, I downloaded this repo and opened it with the same virtual env in VSCode. The same error occurs. I solved the problem by making the datatype optional by changing line 12 in auth_bearer.py to credentials: Optional[HTTPAuthorizationCredentials] = await super(JWTBearer, self).__call__(request). In addition it was necessary to import Optional from typing (from typing import Optional). Can you please check, if this is a proper solution?

My environment is Win10, VSCode, Python 3.9.4, fastapi 0.63.0.

TorstenD69 avatar Apr 15 '21 10:04 TorstenD69

Expression of type "xxx | None" is awailable only in python version >=3.10 see in doc: https://docs.python.org/3/library/stdtypes.html#union-type and watch at the end "New in version 3.10."

Sadbot avatar Mar 30 '22 13:03 Sadbot