deepl-python icon indicating copy to clipboard operation
deepl-python copied to clipboard

mypy complains about not explicitly export attributes from __init__.py

Open derlikh-smart opened this issue 2 years ago • 3 comments

The code

import deepl

translator = deepl.Translator(...)

Produces the following mypy error: error: Module "deepl" does not explicitly export attribute "Translator" [attr-defined]

derlikh-smart avatar Nov 08 '23 13:11 derlikh-smart

Hi, I can't reproduce this (but will add that mypy passes for an example project to our new CI stage). Could you tell me the deepl and mypy versions please?

I tested the following:

mkdir python_test
cd python_test
python3 -m venv .venv
source .venv/bin/activate
pip install deepl mypy
pip freeze
  certifi==2023.7.22
  charset-normalizer==3.3.2
  deepl==1.16.1
  idna==3.4
  mypy==1.6.1
  mypy-extensions==1.0.0
  requests==2.31.0
  typing_extensions==4.8.0
  urllib3==2.0.7
echo "
import deepl

translator = deepl.Translator('abc')" > script.py
mypy script.py
  Success: no issues found in 1 source file

If I use deepl.Translator(...) with the 3 dots, I get

script.py:4: error: Argument 1 to "Translator" has incompatible type "ellipsis"; expected "str"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

JanEbbing avatar Nov 08 '23 14:11 JanEbbing

@JanEbbing I'm having the same issue. In order to reproduce you need implicit_reexport = false or strict = true in mypy configuration

vad avatar Nov 17 '23 15:11 vad

Thanks @vad , I changed our pipeline to use strict mypy checking and fixed this issue, will be in the next patch.

JanEbbing avatar Nov 20 '23 11:11 JanEbbing