Skip to content
This repository has been archived by the owner on Jul 21, 2022. It is now read-only.

Build schema fields from plain annotated class. #4

Merged
merged 26 commits into from
May 3, 2018

Conversation

justanr
Copy link
Owner

@justanr justanr commented Apr 29, 2018

  • Generates fields from class level annotations
  • Ignores ClassVar annotations
  • Handles Optional/Union[T, None] by generating allow_none in the field options
  • Allows registration/overriding of type to field definitions (Registration is provided at local and global level)
  • Field constructors are encouraged to be more than just the field type
  • Allows setting configuration for fields in a meta
  • Will walk parents to find other configurations and combine into a single one
  • Will respect fields that exist in the MRO already --- should there be a force option to override the field?
  • Can auto register the schema itself when a target class is provided and registers as fields.Nested
import typing as t
from marshmallow_annotations import AnnotationSchema

class Frob:
    id: t.Optional[int]
    name: str
  
class Baz:
    frobs: t.List[Frob]

class FrobSchema(AnnotationSchema):
    class Meta:
        target = Frob
        register_as_scheme = True

class BazSchema(AnnotationSchema):
    class Meta:
        target = Baz
        register_as_schema = True

@justanr justanr self-assigned this Apr 29, 2018
@coveralls
Copy link

coveralls commented Apr 29, 2018

Pull Request Test Coverage Report for Build 46

  • 187 of 187 (100.0%) changed or added relevant lines in 6 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 6: 0.0%
Covered Lines: 187
Relevant Lines: 187

💛 - Coveralls

@justanr
Copy link
Owner Author

justanr commented Apr 29, 2018

Few more things:

  • List[Frob] -> Nested(FrobSchema, many=True) gonna punt on this for now, could be too hard for a timely merge
  • Check forward declarations are handled properly forward declarations are fucky right now. :/
  • Write docs

Gonna punt on the default value for now

edit: Of the three bullet points above, docs was the hardest to deal with. shows how much I know. lol

@justanr
Copy link
Owner Author

justanr commented May 1, 2018

If converter grows an is_scheme method, that might solve the List(Nested(...)) issue.

See marshmallow-code/marshmallow#779 for a possible hiccup though.

@justanr
Copy link
Owner Author

justanr commented May 1, 2018

Also, should this back port 3.6.5's get type hints fix?

edit: no, put a note in the docs recommending against forward declarations to target type in <3.6.5 without back porting the fix.

@justanr
Copy link
Owner Author

justanr commented May 2, 2018

update readme, find a way to get mypy to ignore that file for proper depreciation (otherwise full nuclear will be needed), one more pass over docs is needed as well.

@justanr justanr merged commit ba00686 into master May 3, 2018
@justanr justanr deleted the ISS-1-build-from-annotated-class branch May 3, 2018 03:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants