# swegym / python__mypy-15624

- taskset: [swegym](https://harnessreport.com/tasks/swegym.md)
- difficulty: hard
- category: debugging
- language: 
- runnable from the site: no
- agent timeout: 3000s

## Results by harness

_none yet_

## Instruction

```
stubgen: wrong import statements for base module when importing submodule
There's a bug with the import statements generated in .pyi files.

Consider the folder structure:
```
somefolder/
    test.py
    foo_mod/
        __init__.py
        bar_mod.py
```
with file contents:
```python
# test.py
import foo_mod
import foo_mod.bar_mod as bar_mod

class baz(foo_mod.foo, bar_mod.bar):
    pass
```
```python
# foo_mod/__init__.py
class foo:
    pass
```
```python
# foo_mod/bar_mod.py
class bar:
    pass
```
Then running `stubgen test.py` whilst in `somefolder` generates an `out/test.pyi` file with contents:
```python
# out/test.pyi
# Stubs for test (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.

import foo_mod.bar_mod as bar_mod
import foo_mod.bar_mod

class baz(foo_mod.foo, bar_mod.bar): ...
```
Note how it says `foo_mod.bar_mod`, rather than just `foo_mod` as expected.

This issue generalises to subsubpackages as well (and presumably further). That is,
```python
# test.py
import foo_mod
import foo_mod.bar_mod as bar_mod
import foo_mod.bar_mod.quux_mod as quux_mod
...
```
generates
```python
# out/test.pyi
import foo_mod.bar_mod.quux_mod as bar_mod
import foo_mod.bar_mod.quux_mod
import foo_mod.bar_mod.quux_mod as quux_mod
...
```

Tested on Windows and Unix, with both mypy version 0.701 and the latest on the GitHub master branch, with Python 3.6.6. (At least, that's the version of Python which is bound to `python` on the command line, so presumably that's what stubgen is using?)

Possibly related? https://github.com/python/mypy/issues/6831
```
---
Harness Report runs agent harnesses from their GitHub repos on Harbor tasks and records every model call. Every page is also `.md` and `.json`; index: https://harnessreport.com/llms.txt · MCP: https://harnessreport.com/mcp
