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

Expose Python 3 instance attribute annotations where available. #13

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

amcgregor
Copy link
Member

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
Copy link

codecov bot commented Oct 23, 2019

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%> (ø) ⬆️
marrow/schema/release.py 100% <100%> (ø) ⬆️
marrow/schema/declarative.py 100% <100%> (ø) ⬆️

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant