Skip to content

bad-specialization false positive when using partial with a generic decorator #3329

Closed

Description

@superbobry

Describe the Bug

Reproducer:

import functools
from typing import TypeVar, Callable
C = TypeVar("C", bound=Callable)

def api_boundary2(
    fun: C, *,
    s: str | None = None) -> C:
  return fun


@functools.partial(api_boundary2, s="foo")
def test() -> None: ...

Output:

ERROR `GenericResidual@C` is not assignable to upper bound `(...) -> Unknown` of type variable `C` [bad-specialization]
  --> /tmp/foo.py:11:1
   |
11 | @functools.partial(api_boundary2, s="foo")
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |

Removing the bound= from C resolves the issue. The same snippet type checks fine under 0.63.1, but fails under 0.64.0.

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIEAtsbgE4AuABGAK7oDGDuuUcAOujB1cVJg1LEI6AOZNqtRkwAqkmADVUdADRMAwqihRU2WIL1MAvCrWa6ACn4g9T3XnaZLBoydgBKQUFMGDAmVCkAfXcsLVIAJkd0JmSWdkR9XQAqbUEUpjh0uAY6JgAfJgA5XHQYK0rqmD8mAFoAPn1EXKY6GAZWOiS2dEDh9AABIa4ePhItBghDe3CIKNwPWLjdOEsnMB4nAKwQ8XgGeya2%2Bpr0wluQbRAyHrAoUkJuKigKdgliGExmsEwM1sDAABaoABuEHodScHDBMA4AGtmhgAdIwDA6M0en0Bmj0KQnCAAL4PVBcCCQmAAMWgMAoaCweCIZDJQA

(Only applicable for extension issues) IDE Information

No response

Activity

  1. rchen152 commented on May 7, 2026

    @rchen152
    Contributor

    cc @stroxler - this looks like a bug with generic residuals

  2. jorenham commented on May 8, 2026

    @jorenham
    Collaborator

    This looks a lot like a new scipy-stubs error that popped up after upgrading to 0.64.0 (same with 0.64.1) in scipy/scipy-stubs#1589:

    ERROR `float` is not assignable to upper bound `ABCPolyBase` of type variable `_PolyT` [bad-specialization]
      --> tests/optimize/test_minimize_scalar.pyi:23:27
       |
    23 | res_poly = minimize_scalar(p)
       |                           ^^^
       |
    
  3. added this to the v1.2 milestone on Jun 26, 2026
  4. jorenham commented on Jul 14, 2026

    @jorenham
    Collaborator

    Thanks @shobhitmehro !

    Out of curiosity, was there a juicy primer diff for scipy-stubs, or does mypy_primer only run on public PRs or something?

  5. added a commit that references this issue on Jul 14, 2026
  6. added a commit that references this issue on Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions