Skip to content

unexpected attr-defined error in imports in dead code #20408

@dlech

Description

@dlech

Bug Report

mypy still gives an attr-defined error in dead code when importing platform-specific attributes from modules.

To Reproduce

import sys

if sys.platform != "win32":
    assert False

from ctypes import windll

Check it on any OS other than Windows.

Expected Behavior

No errors. This is valid code since it has the platform-specific guard.

Actual Behavior

$ uvx mypy example.py 
example.py:6: error: Module "ctypes" has no attribute "windll"  [attr-defined]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: mypy 1.19.0 (compiled: yes)
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions