Skip to content

Type annotation on method parameter is resolved using attrs class instance variables #20011

@injust

Description

@injust

Bug Report

On an attrs class, mypy appears to resolve the httpx in the method parameter type annotation to the instance variable httpx instead of the module httpx.

To Reproduce

from __future__ import annotations

import httpx
from attrs import define, field


@define
class Foo:
    httpx: httpx.AsyncClient = field(factory=httpx.AsyncClient)

    def bar(self, response: httpx.Response) -> None:
        pass

Expected Behavior

The code should type check.

Actual Behavior

test.py:11: error: Name "httpx.Response" is not defined  [name-defined]

Your Environment

Using attrs 25.4.0

  • Mypy version used: 1.18.2
  • Mypy command-line flags: N/A
  • Python version used: 3.13.5

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions