Skip to content

pyrefly report: typable counts for overloads is too high #3098

@jorenham

Description

@jorenham

In case of

@overload
def f(val: str, /) -> str: ...
@overload
def f(val: bytes, enc: str) -> str: ...

there should be 3 typables:

  • there is 1 val parameter
  • there is 1 enc parameter
  • there is one return type

But Pyrefly currently counts each overload separately and sums the result.
So in this example it'll count val twice, enc once, and the return twice, for a total of 5 typables.

This significantly inflates the number of typables.
In scipy-stubs, for example, Pyrefly reports 50,251 typables, whereas typestats reports 13,428 typables.

So typestats deduplicates the parameters (and trivially, the return types) of overloaded signatures. See https://github.com/jorenham/typestats/blob/5fb1144/src/typestats/analyze.py#L335-L376 for the implementation. It's a bit complex, because for positional-only arguments names are irrelevant, but for pos-or-kw params it both does and doesn't matter, depending on context. To be honest, I'm not 100% certain that this implementation is correct in the most complicated of cases (e.g. in case some overloads have *args/**kwargs, some have pos-or-kw params, and some others have pos-only + kw-only params), but those are probably rare in practice.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions