Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions mypy-relaxed.ini
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
disallow_untyped_decorators = True
warn_unused_ignores = True
warn_return_any = True
strict_equality = True
16 changes: 9 additions & 7 deletions opentelemetry-api/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand All @@ -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,
)
9 changes: 5 additions & 4 deletions opentelemetry-api/src/opentelemetry/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -101,15 +101,16 @@ 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

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)
Expand Down Expand Up @@ -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 <loader-factory>` for more details."""
global _DEFAULT_FACTORY #pylint:disable=global-statement
Expand Down
8 changes: 4 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down