Skip to content

Inlay hint inserting does not avoid name collisions #2802

@MeGaGiGaGon

Description

@MeGaGiGaGon

Summary

Noticed this while messing around with astral-sh/ruff#22111. If you have a name from a different module also defined in the current module, inserting an inlay hint can cause a name collision.
https://play.ty.dev/9a2adb45-8117-49eb-9825-f659ed33ab32
module.py:

class A: ...

main.py:

from dataclasses import dataclass
import module  # Don't import A directly because there's also an A here

class A: ...

@dataclass
class B[T]:
    x: T

b = B(module.A())
# After inserting, oops
# Object of type `B[module.A]` is not assignable to `B[main.A]`
b: B[A] = B(module.A())

This is most common for me with Literal, since sometimes I do just want a Literal in my parser, but could happen with any name.

Version

playground 8a0426676

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingserverRelated to the LSP server

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions