python / python/mypy

Cannot determine type of "userlist"

Open
#11,554 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-import-cycles
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

Unexpected error Cannot determine type of "userlist". Needs a cyclic import to happen.

To Reproduce

foo.py

import bar

class Foo:
    def __init__(self) -> None:
        self.view_selector = object()

bar.py

from foo import Foo

class ServerView:
    def __init__(self) -> None:
        print(ChannelView().userlist)
        self.view_id = str(Foo().view_selector)

class ChannelView:
    def __init__(self) -> None:
        print(ServerView().view_id)
        self.userlist = object()

Expected Behavior

no error, or an error that does not confusingly go away when I delete a seemingly unrelated line of code

Actual Behavior

$ python3 -m mypy foo.py bar.py
bar.py:5: error: Cannot determine type of "userlist"
Found 1 error in 1 file (checked 2 source files)

Your Environment

  • Mypy version used: master (053a1beb94ee4e5b3260725594315d1b6776e42f)
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: doesn't matter, why do you ask?
  • Operating system and version: is a weird question to ask. I am tired of answering this question. But I guess it could be useful in some other issue.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running python3 -m mypy foo.py bar.py on the provided cyclic-import example and compare the userlist error with the expected behavior. Trace how mypy analyzes the Foo, ServerView, and ChannelView definitions in foo.py and bar.py; done means the example no longer produces the confusing Cannot determine type of "userlist" error, or reports a clearer diagnostic.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.