Skip to content
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

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

Closed
AlexWaygood opened this issue Mar 30, 2023 · 0 comments · Fixed by #14984
Closed

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

AlexWaygood opened this issue Mar 30, 2023 · 0 comments · Fixed by #14984
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code topic-stubtest topic-typed-dict

Comments

@AlexWaygood
Copy link
Member

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code topic-stubtest topic-typed-dict
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant