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

JsonObjectMeta: Run __get_fields for each base class #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Test

on: [push, pull_request]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest

steps:
- name: Run pytest
uses: cclauss/[email protected]
4 changes: 1 addition & 3 deletions pykson/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,7 @@ def __get_fields(cls) -> List[Field]:
fields_list.append(field)
for base in cls.__bases__:
base_type_dicts = base.__dict__ # type(self).__dict__
for n, field in base_type_dicts.items():
if isinstance(field, Field):
fields_list.append(field)
fields_list += JsonObjectMeta.__get_fields(base)
return fields_list

@staticmethod
Expand Down
20 changes: 20 additions & 0 deletions test_pykson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pykson

class Class1(pykson.JsonObject):
variable_1 = pykson.IntegerField(default_value=1)

class Class2(Class1):
variable_2 = pykson.IntegerField(default_value=2)

class Class3(Class2):
variable_3 = pykson.IntegerField(default_value=3)

class Class4(Class3):
variable_4 = pykson.IntegerField(default_value=4)

def test_multiple_inheritance():
class4 = Class4()
assert class4.variable_1 == 1
assert class4.variable_2 == 2
assert class4.variable_3 == 3
assert class4.variable_4 == 4