marrow / schema

A generic declarative schema system.
MIT License
6 stars 3 forks source link

Expose Python 3 instance attribute annotations where available. #13

Open amcgregor opened 5 years ago

amcgregor commented 5 years ago

Migrating to Python 3 as the base for the Marrow ecosystem and embracing all of the glorious modern Python 3.7+ features such as type annotations, Marrow Schema Container objects represent a problem. One does not want this:

# Imports **purely** for type annotation.  >_<

from typing import Union

from bson import ObjectId as OID
from collections.abc import MutableMapping
from datetime import datetime, timedelta

# Actual imports.

from marrow.mongo import Document
from marrow.mongo.field import ObjectId

class Foo(Document):
    id: Union[OID,datetime,timedelta,MutableMapping,str,bytes] = ObjectId()

Having users of Marrow Mongo's ObjectId field type be forced to declare such a Union is absurd. Especially while we wait for PEP 563 to become more broadly adopted. (/ wait for Python 4.0). In the Marrow Mongo case, each field type should absolutely be concretely aware of the instance attribute getter/setter type; the metaclass just needs to aggregate and populate the Container.annotations appropriately.

codecov[bot] commented 5 years ago

Codecov Report

Merging #13 into develop will not change coverage. The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop      #13   +/-   ##
========================================
  Coverage    99.54%   99.54%           
========================================
  Files           30       30           
  Lines          879      879           
========================================
  Hits           875      875           
  Misses           4        4
Impacted Files Coverage Δ
marrow/schema/meta.py 100% <100%> (ø) :arrow_up:
marrow/schema/release.py 100% <100%> (ø) :arrow_up:
marrow/schema/declarative.py 100% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 98a0f5d...4485034. Read the comment docs.