Skip to content

name-defined is whitespace-dependentΒ #19632

@injust

Description

@injust

Bug Report

In an attrs class with a field that is named the same as an import, the name-defined check is whitespace-dependent.

To Reproduce

import httpx
from attrs import define, field


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

Expected Behavior

This code should type check identically to:

import httpx
from attrs import define, field


@define
class Foo:
    httpx: httpx.AsyncClient = field(factory=lambda: httpx.AsyncClient())  # on one line

Actual Behavior

test.py:7: error: Name "httpx.AsyncClient" is not defined  [name-defined]

Your Environment

  • Mypy version used: 1.17.1
  • Python version used: 3.13.6
  • attrs version used: 25.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions