Mypy: Implicit re-exports should not be disabled for installed PEP 561 packages

Created on 1 May 2020  路  2Comments  路  Source: python/mypy

With:

  • Python 3.6.10
  • mypy 0.770
  • requests 2.23.0
  • tenacity 6.2.0

the following code:

#!/usr/bin/env python3

from typing import (
    Any,
    Callable,
)

import requests
import tenacity

# Keep trying the request until we connect.
@tenacity.retry(retry=tenacity.retry_if_exception_type(requests.exceptions.ConnectionError))
def retry_if_connection_error(func: Callable[..., requests.Response], *args: Any, **kwargs: Any) -> requests.Response:
    return func(*args, **kwargs)

# Keep trying the request unless we connect.
@tenacity.retry(retry=tenacity.retry_unless_exception_type(requests.exceptions.ConnectionError))
def retry_unless_connection_error(func: Callable[..., requests.Response], *args: Any, **kwargs: Any) -> requests.Response:
    return func(*args, **kwargs)

produces the following output:

$ mypy --strict scripts/dev_test_mypy_tenacity.py
scripts/dev_test_mypy_tenacity.py:12: error: Module has no attribute "retry_if_exception_type"; maybe "retry_if_exception", "retry_unless_exception_type", or "retry_if_exception_message"?
    @tenacity.retry(retry=tenacity.retry_if_exception_type(requests.exceptions.ConnectionError))
                          ^
scripts/dev_test_mypy_tenacity.py:17: error: Module has no attribute "retry_unless_exception_type"; maybe "retry_if_exception_type"?
    @tenacity.retry(retry=tenacity.retry_unless_exception_type(requests.exceptions.ConnectionError))
                          ^
Found 2 errors in 1 file (checked 1 source file)

Note that each error message suggests an alternative that the other error message insists does not exist.

Tenacity only just added the bare minimum of type hints (jd/tenacity#221), so I don't know if there's some conflict there, but even if that's the case, this seems like a bug in mypy.

Possibly related mypy issues: #8220, #8210, #7125, #7029, #6551, #4930

bug false-positive priority-1-normal topic-pep-561

Most helpful comment

This seems to be caused by --no-implicit-reexport. Implicit re-exports should always be allowed in PEP 561 packages, but that's not the case right now.

As a workaround, you can run mypy with --strict --implicit-reexport.

All 2 comments

This seems to be caused by --no-implicit-reexport. Implicit re-exports should always be allowed in PEP 561 packages, but that's not the case right now.

As a workaround, you can run mypy with --strict --implicit-reexport.

Note that https://github.com/python/mypy/pull/9237 should improve the error message here

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Starwort picture Starwort  路  32Comments

JukkaL picture JukkaL  路  41Comments

snakescott picture snakescott  路  27Comments

JukkaL picture JukkaL  路  27Comments

tjltjl picture tjltjl  路  35Comments