Skip to content
Advertisement

mypy – Item “None” of “Optional[CustomAttrsModel]” has no attribute “country”

When I run mypy checkings I am getting an error. I am no able to ignore it or turn it off the strict optional checking. It there a way to solve this.

Here is the line that is throwing the error:

JavaScript

where attributes is declared as:

JavaScript

and CustomAttrsModel is declared as it follows:

JavaScript

Could you please help me with this?

Advertisement

Answer

I had to tweak your snippets a bit to get a MWE, but here we go:

JavaScript

The message is: just use assert something is not None whenever something is Optional ;)

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement