mypy icon indicating copy to clipboard operation
mypy copied to clipboard

BUG: Stubgen removed needed import incorrectly

Open matejsp opened this issue 3 years ago • 0 comments

Bug Report

Using latest mypy 0.971 stub is incorrectly generated (missing import in case of multiple "same imports").

from __future__ import absolute_import

import typing

import stubgenbug.common.circuit_breaker
import stubgenbug.common.typing


class HttpClient(object):
    def __init__(
        self,
        url,  # type: stubgenbug.common.typing.String
        username=None,  # type: typing.Optional[stubgenbug.common.typing.String]
        password=None,  # type: typing.Optional[stubgenbug.common.typing.String]
        breaker=None,  # type: typing.Optional[stubgenbug.common.circuit_breaker.CircuitBreaker]
    ):
        # type: (...) -> None
        pass

Stubgen generates:

import stubgenbug.common.typing
import typing

class HttpClient:
    def __init__(
        self, 
        url: stubgenbug.common.typing.String, 
        username: typing.Optional[stubgenbug.common.typing.String] = ..., 
        password: typing.Optional[stubgenbug.common.typing.String] = ..., 
        breaker: typing.Optional[stubgenbug.common.circuit_breaker.CircuitBreaker] = ...
    ) -> None: ...

Since stubgenbug.common.circuit_breaker was lost in the process stubgenbug.common.circuit_breaker.CircuitBreaker is not resolved.

I am attaching the minimal example. stubgenbug.tar.gz

To Reproduce

Extract attached file and run stubgen stubgenbug -o stubgenbug/out

Expected Behavior

import stubgenbug.common.circuit_breaker should stay in pyi

Your Environment

  • Mypy version used: 0.971
  • Mypy command-line flags: stubgen stubgenbug -o stubgenbug/out
  • Mypy configuration options from mypy.ini (and other config files): /
  • Python version used: 3.8.13
  • Operating system and version: MacOSX 12.5.1

matejsp avatar Sep 14 '22 07:09 matejsp