Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tishka17 committed Nov 1, 2021
2 parents 6582060 + 9f4d0d5 commit 492ed39
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ jobs:
- ubuntu-latest
- macos-latest
- windows-latest
python-version: [3.6, 3.7, 3.8, 3.9]
python-version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"

steps:
- uses: actions/checkout@v2
Expand Down
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

2 changes: 0 additions & 2 deletions dataclass_factory/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ def serializer(self, class_: Type):


class Factory(AbstractFactory):
__slots__ = ("default_schema", "debug_path", "schemas")

def __init__(self,
default_schema: Optional[Schema] = None,
schemas: Optional[Dict[Type, Schema]] = None,
Expand Down
19 changes: 16 additions & 3 deletions dataclass_factory/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def __init__( # noqa C901,CCR001
self.description = description


SCHEMA_FIELDS = [
SCHEMA_FIELDS = {
"only",
"exclude",
"name_mapping",
Expand All @@ -119,27 +119,40 @@ def __init__( # noqa C901,CCR001
"description",
"pre_validators",
"post_validators",
]
}


class _Empty:
pass


class SchemaProxy:
def __init__(self, *schemas: Schema):
self._schemas = schemas
# the first empty object accumulates changes that do not touch actual schema
self._schemas = [_Empty(), *schemas]

def __getattr__(self, item):
for schema in self._schemas:
res = getattr(schema, item, None)
if res is not None:
return res

if item in SCHEMA_FIELDS:
return None

raise AttributeError(f"Field `{item}` is not defined for Schema")

def __setattr__(self, key, value):
if key == "_schemas":
return super().__setattr__(key, value)
return setattr(self._schemas[0], key, value)

def __getstate__(self):
return self._schemas

def __setstate__(self, state):
self._schemas = state


def merge_schema(*schemas: Optional[Schema]) -> Schema:
return cast(Schema, SchemaProxy(*[s for s in schemas if s]))
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ typing_extensions
nose2
mypy
vulture
flake8
flake8==3.*
flake8-blind-except
flake8-bugbear
flake8-builtins
Expand Down

0 comments on commit 492ed39

Please sign in to comment.