Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 677e848

Browse files
Oberon00c24t
authored andcommitted
Lint more files, relax some type checks (open-telemetry#43)
1 parent 69234bd commit 677e848

File tree

5 files changed

+41
-15
lines changed

5 files changed

+41
-15
lines changed

mypy-relaxed.ini

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; This is mainly intended for unit tests and such. So proably going forward, we
2+
; will disable even more warnings here.
3+
[mypy]
4+
disallow_any_unimported = True
5+
; disallow_any_expr = True
6+
disallow_any_decorated = True
7+
disallow_any_explicit = True
8+
disallow_any_generics = True
9+
disallow_subclassing_any = True
10+
disallow_untyped_calls = True
11+
; disallow_untyped_defs = True
12+
disallow_incomplete_defs = True
13+
check_untyped_defs = True
14+
disallow_untyped_decorators = True
15+
allow_untyped_globals = True
16+
; Due to disabling some other warnings, unused ignores may occur.
17+
; warn_unused_ignores = True
18+
warn_return_any = True
19+
strict_equality = True
20+
21+
[mypy-setuptools]
22+
ignore_missing_imports = True

mypy.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
disallow_untyped_decorators = True
1313
warn_unused_ignores = True
1414
warn_return_any = True
15+
strict_equality = True

opentelemetry-api/setup.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515
import os
1616
import setuptools
1717

18-
base_dir = os.path.dirname(__file__)
19-
20-
package_info = {}
21-
with open(os.path.join(base_dir, "src", "opentelemetry", "internal", "version.py")) as f:
22-
exec(f.read(), package_info)
18+
BASE_DIR = os.path.dirname(__file__)
19+
VERSION_FILENAME = os.path.join(
20+
BASE_DIR, "src", "opentelemetry", "internal", "version.py")
21+
PACKAGE_INFO = {}
22+
with open(VERSION_FILENAME) as f:
23+
exec(f.read(), PACKAGE_INFO) #pylint:disable=exec-used
2324

2425
setuptools.setup(
2526
name="opentelemetry-api",
26-
version=package_info["__version__"], # noqa
27+
version=PACKAGE_INFO["__version__"], # noqa
2728
author="OpenTelemetry Authors",
2829
author_email="[email protected]",
2930
classifiers=[
@@ -47,6 +48,7 @@
4748
license="Apache-2.0",
4849
package_dir={"": "src"},
4950
packages=setuptools.find_namespace_packages(where="src"),
50-
url="https://github.com/open-telemetry/opentelemetry-python/tree/master/opentelemetry-api",
51+
url=("https://github.com/open-telemetry/opentelemetry-python"
52+
"/tree/master/opentelemetry-api"),
5153
zip_safe=False,
5254
)

opentelemetry-api/src/opentelemetry/loader.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def my_factory_for_t(api_type: typing.Type[T]) -> typing.Optional[T]:
8080
# code.
8181
#ImplementationFactory = Callable[[Type[_T]], Optional[_T]]
8282

83-
_DEFAULT_FACTORY: Optional[_UntrustedImplFactory] = None
83+
_DEFAULT_FACTORY: Optional[_UntrustedImplFactory[object]] = None
8484

8585
def _try_load_impl_from_modname(
8686
implementation_modname: str, api_type: Type[_T]) -> Optional[_T]:
@@ -101,15 +101,16 @@ def _try_load_impl_from_mod(
101101

102102
implementation_fn = getattr(
103103
implementation_mod,
104-
'get_opentelemetry_implementation') # type: _UntrustedImplFactory
104+
'get_opentelemetry_implementation'
105+
) # type: _UntrustedImplFactory[_T]
105106
except AttributeError:
106107
# TODO Log/warn
107108
return None
108109

109110
return _try_load_impl_from_callback(implementation_fn, api_type)
110111

111112
def _try_load_impl_from_callback(
112-
implementation_fn: _UntrustedImplFactory,
113+
implementation_fn: _UntrustedImplFactory[_T],
113114
api_type: Type[_T]
114115
) -> Optional[_T]:
115116
result = implementation_fn(api_type)
@@ -163,7 +164,7 @@ def _load_impl(
163164
return result
164165

165166
def set_preferred_default_implementation(
166-
implementation_factory: _UntrustedImplFactory) -> None:
167+
implementation_factory: _UntrustedImplFactory[_T]) -> None:
167168
"""Sets a factory function that may be called for any implementation
168169
object. See the :ref:`module docs <loader-factory>` for more details."""
169170
global _DEFAULT_FACTORY #pylint:disable=global-statement

tox.ini

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ changedir =
2222
commands =
2323
; Prefer putting everything in one pylint command to profit from duplication
2424
; warnings.
25-
py37-lint: pylint opentelemetry-api/src/opentelemetry/ opentelemetry-api/tests/
25+
py37-lint: pylint opentelemetry-api/src/opentelemetry/ opentelemetry-api/tests/ opentelemetry-api/setup.py
2626
py37-mypy: mypy opentelemetry-api/src/opentelemetry/
27-
; For test code, we don't want to use the full mypy strictness, so we use its
28-
; default flags instead.
29-
py37-mypy: mypy opentelemetry-api/tests/ --config-file=
27+
; For test code, we don't want to enforce the full mypy strictness
28+
py37-mypy: mypy opentelemetry-api/src/opentelemetry/
29+
py37-mypy: mypy --config-file=mypy-relaxed.ini opentelemetry-api/tests/ opentelemetry-api/setup.py
3030
test: python -m unittest discover
3131

3232
[testenv:docs]

0 commit comments

Comments
 (0)