Skip to content

Stubtest: Many false positives when the runtime has a TypedDict #14983

@AlexWaygood

Description

@AlexWaygood

Bug Report

Given a stub that looks like this:

from typing import Any
from typing_extensions import TypedDict

class DBConfig(TypedDict, total=False):
    ATOMIC_REQUESTS: bool
    AUTOCOMMIT: bool
    CONN_MAX_AGE: int
    DISABLE_SERVER_SIDE_CURSORS: bool
    ENGINE: str
    HOST: str
    NAME: str
    OPTIONS: dict[str, Any] | None
    PASSWORD: str
    PORT: str
    TEST: dict[str, Any]
    TIME_ZONE: str
    USER: str

And a runtime that looks like this:

from typing import Any, Dict, Optional, Union
from typing_extensions import TypedDict

class DBConfig(TypedDict, total=False):
    ATOMIC_REQUESTS: bool
    AUTOCOMMIT: bool
    CONN_MAX_AGE: Optional[int]
    CONN_HEALTH_CHECKS: bool
    DISABLE_SERVER_SIDE_CURSORS: bool
    ENGINE: str
    HOST: str
    NAME: str
    OPTIONS: Optional[Dict[str, Any]]
    PASSWORD: str
    PORT: Union[str, int]
    TEST: Dict[str, Any]
    TIME_ZONE: str
    USER: str

Stubtest emits the following errors, all of which are false positives:

error: dj_database_url.DBConfig is inconsistent, metaclass differs
Stub: in file /home/runner/work/typeshed/typeshed/stubs/dj-database-url/dj_database_url.pyi:-1
N/A
Runtime: in file /tmp/tmpwl18jpo6/lib/python3.10/site-packages/dj_database_url.py:37
<class 'typing_extensions._TypedDictMeta'>

error: dj_database_url.DBConfig.__new__ is inconsistent, stub argument "cls" should be positional-only (rename with a leading double underscore, i.e. "__cls")
Stub: in file /home/runner/work/typeshed/typeshed/stubs/dj-database-url/dj_database_url.pyi:91
def [Self] (cls: Type[Self`0]) -> Self`0
Runtime: in file /tmp/tmpwl18jpo6/lib/python3.10/site-packages/typing_extensions.py:679
def (cls, _typename, _fields=None, /, **kwargs)

error: dj_database_url.DBConfig.__new__ is inconsistent, stub does not have argument "_typename"
Stub: in file /home/runner/work/typeshed/typeshed/stubs/dj-database-url/dj_database_url.pyi:91
def [Self] (cls: Type[Self`0]) -> Self`0
Runtime: in file /tmp/tmpwl18jpo6/lib/python3.10/site-packages/typing_extensions.py:679
def (cls, _typename, _fields=None, /, **kwargs)

error: dj_database_url.DBConfig.__new__ is inconsistent, stub does not have argument "_fields"
Stub: in file /home/runner/work/typeshed/typeshed/stubs/dj-database-url/dj_database_url.pyi:91
def [Self] (cls: Type[Self`0]) -> Self`0
Runtime: in file /tmp/tmpwl18jpo6/lib/python3.10/site-packages/typing_extensions.py:679
def (cls, _typename, _fields=None, /, **kwargs)

This came up in python/typeshed#9975

Expected Behavior

No error should be reported; the TypedDicts are identical.

Your Environment

  • Mypy version used: 1.1.1

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions