Skip to content

Commit

Permalink
Do not clobber explicit annotations.
Browse files Browse the repository at this point in the history
  • Loading branch information
amcgregor committed Oct 21, 2019
1 parent c2a4554 commit 98a0f5d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions marrow/schema/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ def process(name, attr):
# Iteratively process the Element subclass instances and update their definition.
attributes.update(process(k, v) for k, v in attrs.items() if isinstance(v, Element))
attrs['__attributes__'] = odict(sorted(attributes.items(), key=lambda t: t[1].__sequence__))
attrs.setdefault('__annotations__', dict())
attrs['__annotations__'].update({k: v.annotation for k, v in attributes.items() if hasattr(v, 'annotation')})
ann = attrs.setdefault('__annotations__', dict())

for k, v in attributes.items():
if not hasattr(v, 'annotation'): continue # Skip missing or None annotations.
ann.setdefault(k, v.annotation) # If an annotation is already set (explicitly by the developer), skip.

# Construct the new class.
cls = type.__new__(meta, str(name), bases, attrs)
Expand Down

0 comments on commit 98a0f5d

Please sign in to comment.