Skip to content

Simple module with harmless import cycle results in Cannot determine type error #6312

Closed
@russelldavis

Description

@russelldavis

To repro (I'm using mypy 0.660):

In models/__init__.py:

config = object()
from .user import User

In models/user.py:

from . import config
print(config)

class User: ...

It runs fine:

~/tmp/repro$ python3 -c 'import models'
<object object at 0x10eccb1c0>

But mypy fails:

~/tmp/repro$ mypy -m models
models/user.py:2: error: Cannot determine type of 'config'

There are two issues here (I'm happy to file another one to track them separately if that helps):

  1. This should probably be supported by mypy
  2. Regardless of whether this particular case is fixed, the error message should say something about import cycles (looks like there have been several issues similar to this in the past; this probably won't be the last)

Related issues:
#2015
#2016
#1185
#481

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions