Skip to content

Class format of TypedDict does not produce proper coverage #17477

Closed
@sshishov

Description

@sshishov

Bug Report

We are using TypedDict to add the proper coverage and proper types for the codebase where the dictionary with pre-defined keys is used. This should solve the problem, add the proper typing everywhere where this dictionary is used and also increase the total coverage of codebase.

Unfortunately when we are using extensively TypeDicts, we have noticed that the coverage stays the same after applying to the code.

The problem is with the coverage of TypedDict itself, even if it has all the types and values specified, mypy somehow flag it as Any Types on this line

NOTE: At the same time if we convert everything to inline type, then the coverage will be proper 100%.

To Reproduce

from __future__ import annotations

__all__ = ['ChannelTypedDict']

import typing as t


class _RecipientTypedDict(t.TypedDict):
    to: list[str]
    cc: list[str]
    bcc: list[str]


class _DataTypedDict(t.TypedDict):
    recipients: _RecipientTypedDict
    subject: str
    message: str


class ChannelTypedDict(t.TypedDict):
    medium: t.Literal['email']
    data: _DataTypedDict

Expected Behavior

The file with TypedDict definitions should be covered accordingly (in most cases it should have 100% coverage)

Actual Behavior

The file containing TypedDict usually has 50% coverage or around (usually we put types outside of main codebase)
Screenshot 2024-07-04 at 01 14 41Screenshot 2024-07-04 at 01 25 52

Your Environment

  • Mypy version used: mypy 1.10.1 (compiled: no)
  • Mypy command-line flags: --cache-fine-grained (as we are running it with dmypy)
  • Mypy configuration options from mypy.ini (and other config files):
txt_report = "src/mypy-reports"
html_report = "src/mypy-reports"
plugins = [
    "mypy_django_plugin.main",
    "mypy_drf_plugin.main",
    "pydantic.mypy",
]
strict = true
warn_unreachable = true
ignore_missing_imports = true
  • Python version used: Python 3.11.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions