Skip to content

no-matching-overload with list/sorted and map/filter #1970

Description

@AA-Turner

Summary

Error is new in ty 0.0.2, not present in 0.0.1a35. Seems to occur when map / filter are put into list/sorted. Oddly, the first error goes away when directly returning the function call instead of using the temp variable.

A

Playground link: https://play.ty.dev/10c125c1-9480-475a-a076-861ade84c805

Reproducer:

import re
from collections.abc import Iterable
from typing import Any

def func(obj: Any) -> list[str | Any]:
    if isinstance(obj, (list, tuple, set, frozenset)):
        lst = sorted(map(func, obj), key=str) # No overload of function `sorted` matches arguments (no-matching-overload) [Ln 7, Col 15]
        return lst
    return [obj]

def patfilter(names: Iterable[str], pat: str) -> list[str]:
    match = re.compile(pat).match
    return list(filter(match, names))  # No overload of function `__new__` matches arguments (no-matching-overload) [Ln 13, Col 17]

Original output:

error[no-matching-overload]: No overload of function `sorted` matches arguments
  --> sphinx\util\_serialise.py:49:16
   |
47 |     if isinstance(obj, (list, tuple, set, frozenset)):
48 |         # Convert to a sorted list
49 |         return sorted(map(_stable_str_prep, obj), key=str)
   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
50 |     if isinstance(obj, (type, types.FunctionType)):
51 |         # The default repr() of functions includes the ID, which is not ideal.
   |
info: First overload defined here
    --> stdlib\builtins.pyi:4312:5
     |
4311 |   @overload
4312 |   def sorted(
     |  _____^
4313 | |     iterable: Iterable[SupportsRichComparisonT], /, *, key: None = None, reverse: bool = False
4314 | | ) -> list[SupportsRichComparisonT]:
     | |__________________________________^
4315 |       """Return a new list containing all items from the iterable in ascending order.
     |
info: Possible overloads for function `sorted`:
info:   (iterable: Iterable[SupportsRichComparisonT@sorted], *, /, key: None = None, reverse: bool = False) -> list[SupportsRichComparisonT@sorted]
info:   (iterable: Iterable[_T@sorted], *, /, key: (_T@sorted, /) -> SupportsDunderLT[Any] | SupportsDunderGT[Any], reverse: bool = False) -> list[_T@sorted]
info: rule `no-matching-overload` is enabled by default

error[no-matching-overload]: No overload of function `__new__` matches arguments
   --> sphinx\util\matching.py:112:17
    |
110 |         _pat_cache[pat] = re.compile(_translate_pattern(pat))
111 |     match = _pat_cache[pat].match
112 |     return list(filter(match, names))
    |                 ^^^^^^^^^^^^^^^^^^^^
    |
info: First overload defined here
    --> stdlib\builtins.pyi:3623:9
     |
3622 |     @overload
3623 |     def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ...
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3624 |     @overload
3625 |     def __new__(cls, function: Callable[[_S], TypeGuard[_T]], iterable: Iterable[_S], /) -> Self: ...
     |
info: Possible overloads for function `__new__`:
info:   (cls, function: None, iterable: Iterable[_T@filter | None], /) -> Self@__new__
info:   (cls, function: (_S@__new__, /) -> @Todo, iterable: Iterable[_S@__new__], /) -> Self@__new__
info:   (cls, function: (_S@__new__, /) -> TypeIs[_T@filter], iterable: Iterable[_S@__new__], /) -> Self@__new__
info:   (cls, function: (_T@filter, /) -> Any, iterable: Iterable[_T@filter], /) -> Self@__new__
info: rule `no-matching-overload` is enabled by default

Found 2 diagnostics

Version

ty 0.0.2 (4283557 2025-12-16)

Metadata

Metadata

Assignees

Labels

genericsBugs or features relating to ty's generics implementation

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions