Skip to content

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

Closed
@lexdene

Description

@lexdene

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions