Skip to content

Commit 6adb7ac

Browse files
committed
keep mypy and run pyright in standard using strict list
Signed-off-by: emdneto <[email protected]>
1 parent cb2e3f8 commit 6adb7ac

File tree

9 files changed

+124
-33
lines changed

9 files changed

+124
-33
lines changed

.codespellrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[codespell]
22
# skipping auto generated folders
3-
skip = ./.tox,./docs/_build,./target,*/LICENSE,./venv,.git,./opentelemetry-semantic-conventions,*-requirements*.txt
3+
skip = ./.tox,./.mypy_cache,./docs/_build,./target,*/LICENSE,./venv,.git,./opentelemetry-semantic-conventions,*-requirements*.txt
44
ignore-words-list = ans,ue,ot,hist,ro

.github/workflows/misc_0.yml

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,44 @@ jobs:
5252
- name: Run tests
5353
run: tox -e tracecontext
5454

55-
pyright:
56-
name: pyright
55+
mypy:
56+
name: mypy
57+
runs-on: ubuntu-latest
58+
steps:
59+
- name: Checkout repo @ SHA - ${{ github.sha }}
60+
uses: actions/checkout@v4
61+
62+
- name: Set up Python 3.11
63+
uses: actions/setup-python@v5
64+
with:
65+
python-version: "3.11"
66+
67+
- name: Install tox
68+
run: pip install tox
69+
70+
- name: Run tests
71+
run: tox -e mypy
72+
73+
mypyinstalled:
74+
name: mypyinstalled
75+
runs-on: ubuntu-latest
76+
steps:
77+
- name: Checkout repo @ SHA - ${{ github.sha }}
78+
uses: actions/checkout@v4
79+
80+
- name: Set up Python 3.11
81+
uses: actions/setup-python@v5
82+
with:
83+
python-version: "3.11"
84+
85+
- name: Install tox
86+
run: pip install tox
87+
88+
- name: Run tests
89+
run: tox -e mypyinstalled
90+
91+
typecheck:
92+
name: typecheck
5793
runs-on: ubuntu-latest
5894
steps:
5995
- name: Checkout repo @ SHA - ${{ github.sha }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ htmlcov
5656
# Sphinx
5757
_build/
5858

59+
# mypy
60+
.mypy_cache/
5961
target
6062

6163
# Django example

dev-requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pylint==3.2.1
22
httpretty==1.1.4
3-
pyright==1.1.394
3+
pyright==1.1.396
4+
mypy==1.9.0
45
sphinx==7.1.2
56
sphinx-rtd-theme==2.0.0rc4
67
sphinx-autodoc-typehints==1.25.2

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 probably 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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[mypy]
2+
disallow_any_unimported = True
3+
disallow_any_expr = True
4+
disallow_any_decorated = True
5+
; disallow_any_explicit = True
6+
disallow_any_generics = True
7+
disallow_subclassing_any = True
8+
disallow_untyped_calls = True
9+
disallow_untyped_defs = True
10+
disallow_incomplete_defs = True
11+
check_untyped_defs = True
12+
disallow_untyped_decorators = True
13+
warn_unused_configs = True
14+
warn_unused_ignores = True
15+
warn_return_any = True
16+
warn_redundant_casts = True
17+
strict_equality = True
18+
strict_optional = True
19+
no_implicit_optional = True
20+
no_implicit_reexport = True
21+
# https://mypy.readthedocs.io/en/stable/running_mypy.html#follow-imports
22+
follow_imports = silent

pyproject.toml

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,6 @@
22
addopts = "-rs -v"
33
log_cli = true
44

5-
[tool.pyright]
6-
typeCheckingMode = "strict"
7-
include = [
8-
"opentelemetry-api/src",
9-
"opentelemetry-sdk/src",
10-
"opentelemetry-semantic-conventions/src",
11-
"opentelemetry-proto/src",
12-
"scripts"
13-
]
14-
ignore = [
15-
"docs/**",
16-
"exporter/**",
17-
"propagator/**",
18-
"shim/**",
19-
]
20-
reportUnnecessaryTypeIgnoreComment = true
21-
pythonVersion = "3.9"
22-
reportPrivateUsage = false # Ignore private attributes added by instrumentation packages.
23-
24-
exclude = [
25-
"tests/**",
26-
]
27-
285
[tool.ruff]
296
# https://docs.astral.sh/ruff/configuration/
307
target-version = "py38"
@@ -63,3 +40,18 @@ known-third-party = [
6340
"opencensus",
6441
]
6542
known-first-party = ["opentelemetry", "opentelemetry_example_app"]
43+
44+
[tool.pyright]
45+
typeCheckingMode = "standard"
46+
pythonVersion = "3.8"
47+
reportPrivateUsage = false
48+
49+
include = [
50+
"opentelemetry-semantic-conventions",
51+
"opentelemetry-api",
52+
]
53+
54+
# When packages are correct typed add them to the strict list
55+
strict = [
56+
"opentelemetry-semantic-conventions",
57+
]

pyright-requirements.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

tox.ini

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ envlist =
8888

8989
spellcheck
9090
tracecontext
91-
pyright
91+
mypy,mypyinstalled
92+
typecheck
9293
docs
9394
docker-tests-{otlpexporter,opencensus}
9495
public-symbols-check
@@ -102,7 +103,8 @@ deps =
102103
coverage: pytest
103104
coverage: pytest-cov
104105

105-
mypy,mypyinstalled: -r {toxinidir}/mypy-requirements.txt
106+
mypy,mypyinstalled: -c {toxinidir}/dev-requirements.txt
107+
mypy,mypyinstalled: mypy
106108

107109
api: -r {toxinidir}/opentelemetry-api/test-requirements.txt
108110

@@ -143,6 +145,7 @@ deps =
143145

144146
propagator-jaeger: -r {toxinidir}/propagator/opentelemetry-propagator-jaeger/test-requirements.txt
145147

148+
mypyinstalled: -e {toxinidir}/opentelemetry-api
146149

147150
getting-started: -r {toxinidir}/docs/getting_started/tests/requirements.txt
148151
getting-started: {env:CONTRIB_REPO}\#egg=opentelemetry-util-http&subdirectory=util/opentelemetry-util-http
@@ -158,7 +161,7 @@ setenv =
158161
; i.e: CONTRIB_REPO_SHA=dde62cebffe519c35875af6d06fae053b3be65ec tox -e <env to test>
159162
CONTRIB_REPO_SHA={env:CONTRIB_REPO_SHA:main}
160163
CONTRIB_REPO=git+https://github.com/open-telemetry/opentelemetry-python-contrib.git@{env:CONTRIB_REPO_SHA}
161-
164+
mypy: MYPYPATH={toxinidir}/opentelemetry-api/src/:{toxinidir}/opentelemetry-semantic-conventions/src/:{toxinidir}/opentelemetry-sdk/src/:{toxinidir}/tests/opentelemetry-test-utils/src/
162165
commands_pre =
163166
; In order to get a healthy coverage report,
164167
; we have to install packages in editable mode.
@@ -227,7 +230,18 @@ commands =
227230

228231
coverage: {toxinidir}/scripts/coverage.sh
229232

230-
233+
mypy: mypy --version
234+
mypy: mypy --install-types --non-interactive --namespace-packages --explicit-package-bases opentelemetry-api/src/opentelemetry/
235+
mypy: mypy --install-types --non-interactive --namespace-packages --explicit-package-bases opentelemetry-sdk/src/opentelemetry/sdk/resources
236+
mypy: mypy --install-types --non-interactive --namespace-packages --explicit-package-bases opentelemetry-semantic-conventions/src/opentelemetry/semconv/
237+
238+
; For test code, we don't want to enforce the full mypy strictness
239+
mypy: mypy --install-types --non-interactive --namespace-packages --config-file=mypy-relaxed.ini opentelemetry-api/tests/
240+
241+
; Test that mypy can pick up typeinfo from an installed package (otherwise,
242+
; implicit Any due to unfollowed import would result).
243+
mypyinstalled: mypy --install-types --non-interactive --namespace-packages opentelemetry-api/tests/mypysmoke.py --strict
244+
231245
[testenv:spellcheck]
232246
basepython: python3
233247
recreate = True
@@ -335,10 +349,13 @@ commands =
335349
[testenv:typecheck]
336350
basepython: python3
337351
deps =
338-
-r {toxinidir}/pyright-requirements.txt
352+
-c {toxinidir}/dev-requirements.txt
353+
pyright
354+
psutil
339355
-e {toxinidir}/opentelemetry-api
340356
-e {toxinidir}/opentelemetry-semantic-conventions
341357
-e {toxinidir}/opentelemetry-sdk
358+
-e {toxinidir}/tests/opentelemetry-test-utils
342359
commands =
343360
pyright --version
344361
pyright

0 commit comments

Comments
 (0)