1

I cannot seem to figure out why mypy is throwing an error on own module import.

$ python -m mypy ./reader/api/response/response.py
reader/api/response/response.py:5: error: Skipping analyzing 'reader.api.response.answer': found module but no type hints or library stubs
reader/api/response/response.py:5: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)

The response.py imports a class from another module in the same repository

from __future__ import annotations

from typing import List
from dataclasses import dataclass
from reader.api.response.answer import Answer  # <- mypy fails here.


@dataclass
class ReaderResponse:
...

The content of answer.py is this:

from __future__ import annotations

from dataclasses import dataclass, fields


@dataclass
class Answer:

    answer: str
    score: float
    source: str
    url: str
    type: str

...

Why does mypy think there are no type hints in my imported module? I have read the documentation on missing imports here, but don't understand how does that apply. It is not a third-party library. It's my own module.

Any clues what am I doing wrong here?

Thank you.

Edit: So switching from namespace packages to regular ones, and switching to relative imports (dot-imports) fixed my problems. Not exactly sure why...

mkserge
  • 93
  • 4

0 Answers0