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

Unexpected inheritance behavior #805

Open
RoTorEx opened this issue Jan 21, 2025 · 0 comments
Open

Unexpected inheritance behavior #805

RoTorEx opened this issue Jan 21, 2025 · 0 comments

Comments

@RoTorEx
Copy link

RoTorEx commented Jan 21, 2025

Description

Hi there,

Why doesn't it work as imagined, especially in the second stage?

from datetime import datetime

import msgspec


element = {
    "id_": 1,
    "name": "Google",
    "country": "Finland",
    "description": None,
    "created_at": datetime(2025, 1, 20, 12, 28, 55),
    "updated_at": datetime(2025, 1, 20, 18, 58, 42),
}


# Stage ONE
class _FooOne(msgspec.Struct):
    id_: int
    created_at: datetime
    updated_at: datetime


class _BarOne(msgspec.Struct):
    name: str
    country: str
    description: str | None


# class SchemaOne(msgspec.Struct, _FooOne, _BarOne):  # ! TypeError
#     pass


# Stage TWO
class _FooTwo:
    id_: int
    created_at: datetime
    updated_at: datetime


class _BarTwo:
    name: str
    country: str
    description: str | None


class SchemaTwo(_FooTwo, _BarTwo, msgspec.Struct):
    pass


# Stage THREE
class _FooThree(msgspec.Struct):
    id_: int
    created_at: datetime
    updated_at: datetime


class _BarThree(_FooThree):
    name: str
    country: str
    description: str | None


class SchemaThree(_BarThree):
    pass


print(msgspec.convert(element, type=SchemaTwo))  # ! Empty
print(msgspec.convert(element, type=SchemaThree))  # ! Ok
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant