diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 00000000000..5899d1954e0 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,14 @@ +[mypy] + disallow_any_unimported = True + disallow_any_expr = True + disallow_any_decorated = True + disallow_any_explicit = True + disallow_any_generics = True + disallow_subclassing_any = True + disallow_untyped_calls = True + disallow_untyped_defs = True + disallow_incomplete_defs = True + check_untyped_defs = True + disallow_untyped_decorators = True + warn_unused_ignores = True + warn_return_any = True diff --git a/opentelemetry-api/opentelemetry/__init__.py b/opentelemetry-api/opentelemetry/__init__.py new file mode 100644 index 00000000000..d853a7bcf65 --- /dev/null +++ b/opentelemetry-api/opentelemetry/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2019, OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/opentelemetry-api/opentelemetry/trace/__init__.py b/opentelemetry-api/opentelemetry/trace/__init__.py index 282bc72b3f0..e1bda185a73 100644 --- a/opentelemetry-api/opentelemetry/trace/__init__.py +++ b/opentelemetry-api/opentelemetry/trace/__init__.py @@ -63,7 +63,7 @@ """ from contextlib import contextmanager -from typing import Iterator +import typing class Tracer: @@ -85,8 +85,8 @@ def get_current_span(self) -> 'Span': """ - @contextmanager - def start_span(self, name: str, parent: 'Span') -> Iterator['Span']: + @contextmanager # type: ignore + def start_span(self, name: str, parent: 'Span') -> typing.Iterator['Span']: """Context manager for span creation. Create a new child of the current span, or create a root span if no @@ -154,8 +154,8 @@ def create_span(self, name: str, parent: 'Span') -> 'Span': The newly-created span. """ - @contextmanager - def use_span(self, span: 'Span') -> Iterator[None]: + @contextmanager # type: ignore + def use_span(self, span: 'Span') -> typing.Iterator[None]: """Context manager for controlling a span's lifetime. Start the given span and set it as the current span in this tracer's @@ -229,5 +229,5 @@ class TraceOptions(int): # TODO -class TraceState(dict): +class TraceState(typing.Dict[str, str]): pass diff --git a/opentelemetry-api/setup.py b/opentelemetry-api/setup.py index 2e405905aae..460417304ff 100644 --- a/opentelemetry-api/setup.py +++ b/opentelemetry-api/setup.py @@ -41,6 +41,7 @@ include_package_data=True, long_description=open("README.rst").read(), install_requires=[ + "typing; python_version<'3.5'", ], extras_require={}, license="Apache-2.0", diff --git a/tox.ini b/tox.ini index edfece5971f..aa70cf3b3ec 100644 --- a/tox.ini +++ b/tox.ini @@ -1,10 +1,12 @@ [tox] skipsdist = True -envlist = py37-lint +envlist = py37-lint, py37-mypy [testenv] deps = py37-lint: pylint + py37-mypy: mypy commands = - py37-lint: pylint opentelemetry-api/opentelemetry/trace/ + py37-lint: pylint opentelemetry-api/opentelemetry/ + py37-mypy: mypy opentelemetry-api/opentelemetry/