8000 "Unexpected keyword argument" for custom dataclasses · Issue #6239 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content 8000
"Unexpected keyword argument" for custom dataclasses #6239
Closed
@samuelcolvin

Description

@samuelcolvin

I'm wonder if I can get pydantic's custom dataclasses to work with mypy, original issue: pydantic/pydantic#280.

The following code passes mpy validation:

from dataclasses import dataclass
# from pydantic.dataclasses import dataclass

@dataclass
class Test:
    test_int: int
    test_str: str

Test(test_int=42, test_str='foobar')

However, if I change the import to use from pydantic.dataclasses import dataclass I get

> mypy --follow-imports=skip test.py
test.py:9: error: Unexpected keyword argument "test_int" for "Test"
test.py:9: error: Unexpected keyword argument "test_str" for "Test

Is this because mypy does somethign special when it seems the standard library dataclasses import, or because of something erroueous in pydantic's dataclass implementation (code here).

Either way, is there anything I can do to fix this in pydantic?

The class returned by pydantic's @dataclass decorator should be (almost) identical to the standard lib decorator as it uses dataclasses._process_class() internally.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0