Skip to content

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

Open

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

Activity

  1. A5rocks commented on Dec 14, 2025

    @A5rocks
    Collaborator

    I'm fairly certain this will be fixed by #18539 (though I need to recreate that PR to fix CI...)

  2. A5rocks commented on Dec 15, 2025

    @A5rocks
    Collaborator

    Actually I'll keep this open because this is top level + not by return, even if I suspect the same issue is the problem...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-reachabilityDetecting unreachable code

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions