mypy icon indicating copy to clipboard operation
mypy copied to clipboard

stubgen: mangles from _typeshed import Incomplete on Windows

Open Josverl opened this issue 2 years ago • 12 comments

Bug Report When stubgen creates stubs for a module that imports Incomplete , it then mangles / overcomplicates the import in the generated stub edit : On Windows

To Reproduce - minimal repro

from _typeshed import Incomplete


def polar(*args, **kwargs) -> Incomplete:
    ...

running stubgen results in

from _typeshed import Incomplete as Incomplete

def polar(*args, **kwargs) -> Incomplete: ...

Environment

  • Mypy version used: 1.7.0
  • Mypy command-line flags: - none
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.11
  • OS: Windows_NT x64 10.0.26100

Josverl avatar Dec 12 '23 23:12 Josverl

@Josverl hi! I think it's outdated issue

makridenko avatar May 22 '25 12:05 makridenko

I can prove it still reproduces with stubgen 1.15.0.

@makridenko Why do you think it is outdated ?

Josverl avatar May 22 '25 16:05 Josverl

@Josverl I've tried to reproduce it with master-branch stubgen and it works fine. I guess we need to wait for release

makridenko avatar May 22 '25 16:05 makridenko

Perhaps to be clearer The bug is the 2x Incomplete in Incomplete as Incomplete

Expected

from _typeshed import Incomplete

def polar(*args, **kwargs) -> Incomplete

So the bug is still not resolved.

Josverl avatar May 22 '25 21:05 Josverl

In master branch everything is working as expected:

Image

makridenko avatar Jun 08 '25 11:06 makridenko

Do we have a test case for that?

sobolevn avatar Jun 08 '25 11:06 sobolevn

@sobolevn I can add the test that's in the screenshot above

makridenko avatar Jun 08 '25 11:06 makridenko

@sobolevn https://github.com/python/mypy/pull/19253

makridenko avatar Jun 08 '25 11:06 makridenko

Ill verify the current state as I can't explain why the behavior is different for @makridenko than for me. Also the previous reported behavior by @makridenko was same as mine, so something changed....

That might also mean that the test case is not covering the all relevant aspects.

Ill report back here.

Josverl avatar Jun 08 '25 11:06 Josverl

@sobolevn Im sorry , but i need to report that the issue indeed is not fixed. The same issue still occurs, but appears to be specific to stubgen running on Windows. I did not include that in my initial report, as I assumed that that would not matter.

Is stubgen tested on anything but Ubuntu ? ( there are a lot of tests skipped on Windows)

See : https://github.com/Josverl/mypy_mangle

Josverl avatar Jun 09 '25 21:06 Josverl

@Josverl thank you for clarifying this, unfortunately I don't have any windows machine. @sobolevn could you test this?

makridenko avatar Jun 09 '25 21:06 makridenko

a few points.

  1. The tests that was added is part of a suite that is skipped on Windows. ( along with the rest of the suite)
        
        pytest  mypy\test\teststubgen.py::StubgenPythonSuite::stubgen.test::testIncompleteReturn
        ========================================================================= test session starts ==========================================================================
        platform win32 -- Python 3.11.9, pytest-8.3.5, pluggy-1.5.0
        rootdir: D:\mypython\!-stubtestprojects\mypy_mangle\mypy
        configfile: pyproject.toml
        plugins: anyio-4.6.0, time-machine-2.16.0
        collected 1 item                                                                                                                                                        
        
        mypy\test\teststubgen.py s                                                                                                                                        [100%] 
        
        ========================================================================== 1 skipped in 0.44s ==========================================================================
  1. When I remove that skipif guard , the tests passes, but the stubgen behaviour is still incorrect.

Josverl avatar Jun 10 '25 16:06 Josverl

Any progress on replication of this issue?

Josverl avatar Jun 24 '25 18:06 Josverl