Add type annotations to storage API #1410
@@ Coverage Diff @@ ## trunk #1410 +/- ## ========================================== + Coverage 86.46% 86.46% +<.01% ========================================== Files 366 366 Lines 76791 76794 +3 Branches 7529 7529 ========================================== + Hits 66396 66399 +3 Misses 7527 7527 Partials 2868 2868
What's your take on utilizing Python 3 native syntax for type annotations vs using comments?
In theory, using comments, allows the trunk to still work with Python 2.7, but since we don't officially support it any more, I'm not sure if that matters or not since sooner or later we will likely start utilizing other Python 3 only features as well (and we have v2.8.x branch we can base v2.8.x bug fix release on, if needed).
@Kami Personally I'm not a huge fan of the type comments for function signatures and would be in favor of eventually switching to the native type annotations to increase readability.
E.g. compare the following two snippets:
def upload_object_via_stream(self, iterator, object_name, extra=None, headers=None): # type: (Iterator[bytes], str, Optional[dict], Optional[Dict[str, str]]) -> Object # noqa: E501
def upload_object_via_stream(self, iterator: Iterator[bytes], object_name: str, extra: Optional[dict] = None, headers: Optional[Dict[str, str]] = None, ) -> Object:
From my point of view, the former is harder to read since the function arguments must be matched with the type declaration based on index/position as opposed to being attached to each argument explicitly.
@c-w Good catch on the headers issue
As far as comments notation goes - in-line annotations can also be used when using comments, but I also agree that native notation is nicer.
So perhaps now that we don't need to support Python 2.7 anymore, we can just switch to that notation.