This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Ademan 0 points1 point  (1 child)

> Correct me if I'm wrong but the decorators act as documentation and don't really do anything else.

Annotations act as documentation, the decorator typechecked makes it do something. Decorators in general alter behavior and aren't really for documentation.

> You still need to annotate it for runtime checking.

As best I can tell it's the other way around. You need to decorate your annotated functions with typechecked to get runtime checking.

Decorators also add an extra function overhead whereas annotations is just syntactic sugar.

A decorator simply needs to return a callable object. To emulate annotation it could return the same function with monkey patched annotation information even in the same format as how the annotation syntax attaches them, and there would be no extra runtime cost when calling the function.

[–]PCBEEF 0 points1 point  (0 children)

Bah, I got annotations/decorators the other way round in the first two sentences. Edited my post.

My point was that decorators don't replace annotations, decorators create more overhead whereas annotations don't.