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

Fix bug with multiple generic inheritence #626

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions msgspec/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,12 @@ def inner(c, scope):
new_scope = {}
else:
cls = getattr(c, "__origin__", None)
if cls in (None, object, typing.Generic):
if cls in (None, object, typing.Generic) or cls in mapping:
return
if cls not in mapping:
params = cls.__parameters__
args = tuple(_apply_params(a, scope) for a in c.__args__)
assert len(params) == len(args)
mapping[cls] = new_scope = dict(zip(params, args))
params = cls.__parameters__
args = tuple(_apply_params(a, scope) for a in c.__args__)
assert len(params) == len(args)
mapping[cls] = new_scope = dict(zip(params, args))

if issubclass(cls, typing.Generic):
bases = getattr(cls, "__orig_bases__", cls.__bases__)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,12 @@ class Sub3(Sub[List[T]]):
"a": List[List[int]],
"b": List[int],
}

def test_generic_sub11(self):
class Sub(Base[int]):
y: float

class Sub2(Sub, Base[int]):
z: str

assert get_class_annotations(Sub2) == {"x": int, "y": float, "z": str}
Loading