Skip to content

[1.16 regression] Internal error: must never apply partial type #19213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lexdene opened this issue Jun 3, 2025 · 3 comments · Fixed by #19216
Closed

[1.16 regression] Internal error: must never apply partial type #19213

lexdene opened this issue Jun 3, 2025 · 3 comments · Fixed by #19216
Labels

Comments

@lexdene
Copy link

lexdene commented Jun 3, 2025

Crash Report

mypy crash with message:

Internal error: must never apply partial type

Traceback

main.py:19: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 1.16.0
Traceback (most recent call last):
  File "mypy/checkexpr.py", line 5926, in accept
  File "mypy/nodes.py", line 2018, in accept
  File "mypy/checkexpr.py", line 488, in visit_call_expr
  File "mypy/checkexpr.py", line 622, in visit_call_expr_inner
  File "mypy/checkexpr.py", line 1478, in check_call_expr_with_callee_type
  File "mypy/checkexpr.py", line 1591, in check_call
  File "mypy/checkexpr.py", line 2724, in check_overload_call
  File "mypy/checkexpr.py", line 2885, in infer_overload_return_type
  File "mypy/checkexpr.py", line 1580, in check_call
  File "mypy/checkexpr.py", line 1752, in check_callable_call
  File "mypy/checkexpr.py", line 2054, in infer_function_type_arguments_using_context
  File "mypy/checkexpr.py", line 3260, in apply_generic_arguments
  File "mypy/applytype.py", line 112, in apply_generic_arguments
AssertionError: Internal error: must never apply partial type
main.py:19: : note: use --pdb to drop into pdb

To Reproduce

main.py:

from typing import overload, TypeVar, Optional, Protocol

T = TypeVar('T')


class DbManager(Protocol):
    @overload
    def get(self, key: str) -> Optional[T]:
        pass

    @overload
    def get(self, key: str, default: T) -> T:
        pass


class Foo:
    def __init__(self, db: DbManager, bar: bool):
        if bar:
            self.qux = db.get('qux')
        else:
            self.qux = {}

run mypy:

mypy --show-traceback main.py

Your Environment

  • Mypy version used: 1.16.0
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.11.1
  • Operating system and version: Ubuntu 20.04.6 LTS

with mypy 1.15.0, I got error:

main.py:21: error: Need type annotation for "qux" (hint: "qux: dict[<type>, <type>] = ...")  [var-annotated]
Found 1 error in 1 file (checked 1 source file)

But with mypy 1.16.0, I got error:

main.py:19: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
If this issue continues with mypy master, please report a bug at https://github.com/python/mypy/issues
version: 1.16.0
main.py:19: : note: please use --show-traceback to print a traceback when reporting a bug
@lexdene lexdene added the crash label Jun 3, 2025
@hauntsaninja hauntsaninja changed the title Internal error: must never apply partial type [1.16 regression] Internal error: must never apply partial type Jun 3, 2025
@hauntsaninja
Copy link
Collaborator

Thanks for the report, bisects to #18847

@sterliakov
Copy link
Collaborator

The snippet has obvious typing error, but hard crash is certainly too much... MRE without overload:

from typing import TypeVar, Protocol

T = TypeVar('T')

class DbManager(Protocol):
    def get(self, key: str) -> T | None:
        pass

class Foo:
    def __init__(self, db: DbManager) -> None:
        self.qux = db.get('qux')

Note that T instead of T | None prevents crash.

@ilevkivskyi
Copy link
Member

@sterliakov Essentially the crash happens in the case where the outer (return) type context is used. I used the original example in the test before seeing your comment, but I think it is OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants