Mypy(union-attr): mypy complains about missing attribute of object of type Optional even after checking that the argument is not None
I need to call a certain method on the argument of an union when used a member of a class which in
I have a data class having as member a list of objects of another class having as member an object of type Optional[CustomType]
as member, and I need to call a method of CustomType
class on that member, only when the member is not None
.
Even if such check is explicitly performed, mypy still complains about the missing attribute of the item None
of the CustomType | None
union.