Skip to content

Differentiate between identically named (but distinct) types in diagnostics #848

@Andre-Medina

Description

@Andre-Medina

Context

When you have two types of the same name from different packages/ parts of the code base Ty will only give the error based on type name, and not its dir, leading to ambiguous errors.

I suggest adding some extra logic to be able to easier differentiate between identically named types, so in the case that it finds this issue, it appends something about the dir of the type.

Example

Say I have a function which expects a polars dataframe but a pandas dataframe is passed:

import polars as pl
import pandas as pd

def polars_function(df: pl.DataFrame) -> pl.DataFrame:
    return df

df_pd = pd.DataFrame()
polars_function(df_pd)

Will receive this ambiguous error:
Image

Solution

Would be very helpful if ty noticed that DataFrame and DataFrame are the same name and then appended the package name/ dir as follows:

 --> test_file.py:8:17
  |
7 | df_pd = pd.DataFrame()
8 | polars_function(df_pd)
  |                 ^^^^^ Expected `polars.DataFrame`, found `pandas.DataFrame`

Version

ty 0.0.1-alpha.14

Metadata

Metadata

Assignees

No one assigned

    Labels

    diagnosticsRelated to reporting of diagnostics.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions