For example this mixin:
from lib import stringlib
class NiceNameMixin:
@property
def nice_first_name(self):
return stringlib.clean_name(self.first_name)
@property
def nice_last_name(self):
return stringlib.clean_name(self.last_name)
warns me:
Cannot access member "first_name" for type "NiceNameMixin" Member "first_name" is unknown.
What is the correct was of telling the type checker that the attributes self.first_name
and self.last_name
will exist, and it's okay?
Note I normally just # type: ignore
these kind of things, but I am starting to think there must be a more suitable way.
Note: Using Pyright
Update: Class property example for @chepner
from rest_framework import serializers
class UtilsMixin:
@classproperty
def model_class(cls: serializers.ModelSerializer): # Type of parameter Cls must be a supertype of its class "UtilsMixin"
return cls.Meta.model # Cannot access member "Meta" for type "ModelSerializer" Member "Meta" is unknown