diff --git a/mypy-relaxed.ini b/mypy-relaxed.ini new file mode 100644 index 00000000000..8f2be85affc --- /dev/null +++ b/mypy-relaxed.ini @@ -0,0 +1,22 @@ +; This is mainly intended for unit tests and such. So proably going forward, we +; will disable even more warnings here. +[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 + allow_untyped_globals = True +; Due to disabling some other warnings, unused ignores may occur. +; warn_unused_ignores = True + warn_return_any = True + strict_equality = True + +[mypy-setuptools] + ignore_missing_imports = True diff --git a/mypy.ini b/mypy.ini index 5899d1954e0..5b46777838d 100644 --- a/mypy.ini +++ b/mypy.ini @@ -12,3 +12,4 @@ disallow_untyped_decorators = True warn_unused_ignores = True warn_return_any = True + strict_equality = True diff --git a/opentelemetry-api/setup.py b/opentelemetry-api/setup.py index de97ec88c14..d2a27a0d442 100644 --- a/opentelemetry-api/setup.py +++ b/opentelemetry-api/setup.py @@ -15,15 +15,16 @@ import os import setuptools -base_dir = os.path.dirname(__file__) - -package_info = {} -with open(os.path.join(base_dir, "src", "opentelemetry", "internal", "version.py")) as f: - exec(f.read(), package_info) +BASE_DIR = os.path.dirname(__file__) +VERSION_FILENAME = os.path.join( + BASE_DIR, "src", "opentelemetry", "internal", "version.py") +PACKAGE_INFO = {} +with open(VERSION_FILENAME) as f: + exec(f.read(), PACKAGE_INFO) #pylint:disable=exec-used setuptools.setup( name="opentelemetry-api", - version=package_info["__version__"], # noqa + version=PACKAGE_INFO["__version__"], # noqa author="OpenTelemetry Authors", author_email="cncf-opentelemetry-contributors@lists.cncf.io", classifiers=[ @@ -47,6 +48,7 @@ license="Apache-2.0", package_dir={"": "src"}, packages=setuptools.find_namespace_packages(where="src"), - url="https://github.com/open-telemetry/opentelemetry-python/tree/master/opentelemetry-api", + url=("https://github.com/open-telemetry/opentelemetry-python" + "/tree/master/opentelemetry-api"), zip_safe=False, ) diff --git a/opentelemetry-api/src/opentelemetry/loader.py b/opentelemetry-api/src/opentelemetry/loader.py index dc3a4e078e9..3c2fdcab6ac 100644 --- a/opentelemetry-api/src/opentelemetry/loader.py +++ b/opentelemetry-api/src/opentelemetry/loader.py @@ -80,7 +80,7 @@ def my_factory_for_t(api_type: typing.Type[T]) -> typing.Optional[T]: # code. #ImplementationFactory = Callable[[Type[_T]], Optional[_T]] -_DEFAULT_FACTORY: Optional[_UntrustedImplFactory] = None +_DEFAULT_FACTORY: Optional[_UntrustedImplFactory[object]] = None def _try_load_impl_from_modname( implementation_modname: str, api_type: Type[_T]) -> Optional[_T]: @@ -101,7 +101,8 @@ def _try_load_impl_from_mod( implementation_fn = getattr( implementation_mod, - 'get_opentelemetry_implementation') # type: _UntrustedImplFactory + 'get_opentelemetry_implementation' + ) # type: _UntrustedImplFactory[_T] except AttributeError: # TODO Log/warn return None @@ -109,7 +110,7 @@ def _try_load_impl_from_mod( return _try_load_impl_from_callback(implementation_fn, api_type) def _try_load_impl_from_callback( - implementation_fn: _UntrustedImplFactory, + implementation_fn: _UntrustedImplFactory[_T], api_type: Type[_T] ) -> Optional[_T]: result = implementation_fn(api_type) @@ -163,7 +164,7 @@ def _load_impl( return result def set_preferred_default_implementation( - implementation_factory: _UntrustedImplFactory) -> None: + implementation_factory: _UntrustedImplFactory[_T]) -> None: """Sets a factory function that may be called for any implementation object. See the :ref:`module docs ` for more details.""" global _DEFAULT_FACTORY #pylint:disable=global-statement diff --git a/tox.ini b/tox.ini index 20eb439414c..bd2dae1c566 100644 --- a/tox.ini +++ b/tox.ini @@ -22,11 +22,11 @@ changedir = commands = ; Prefer putting everything in one pylint command to profit from duplication ; warnings. - py37-lint: pylint opentelemetry-api/src/opentelemetry/ opentelemetry-api/tests/ + py37-lint: pylint opentelemetry-api/src/opentelemetry/ opentelemetry-api/tests/ opentelemetry-api/setup.py py37-mypy: mypy opentelemetry-api/src/opentelemetry/ -; For test code, we don't want to use the full mypy strictness, so we use its -; default flags instead. - py37-mypy: mypy opentelemetry-api/tests/ --config-file= +; For test code, we don't want to enforce the full mypy strictness + py37-mypy: mypy opentelemetry-api/src/opentelemetry/ + py37-mypy: mypy --config-file=mypy-relaxed.ini opentelemetry-api/tests/ opentelemetry-api/setup.py test: python -m unittest discover [testenv:docs]