Kaizen Today I Learned by Ville Säävuori

Posts tagged typing

Casting Types With MyPy

Typing in Python is not yet very mature. This small example displays several issues: if request.user.is_authenticated: return JsonResponse( { "user": { "uid": request.user.uid, "username": request.user.username, "email": request.user.email, } } ) The original type of request.user is Union[AbstractBaseUser, AnonymousUser] (which itself is already wrong; the user is actually a Django model that inherits from AbstractBaseUser, not AbstractBaseUser).

· Read the full article →