Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
6 changes: 3 additions & 3 deletions .github/workflows/misc_0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ jobs:
- name: Run tests
run: tox -e mypyinstalled

pyright:
name: pyright
typecheck:
name: typecheck
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
Expand All @@ -104,7 +104,7 @@ jobs:
run: pip install tox

- name: Run tests
run: tox -e pyright
run: tox -e typecheck

docs:
name: docs
Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ You can run `tox` with the following arguments:
- `tox -e lint-some-package` to run lint checks on `some-package`
- `tox -e generate-workflows` to run creation of new CI workflows if tox environments have been updated
- `tox -e ruff` to run ruff linter and formatter checks against the entire codebase
- `tox -e typecheck` to run pyright against entire code base.
- `tox -e public-symbols-check` to run public_symbols_checker.py.
- `tox -e docker-tests-{otlpexporter,opencensus}` to run tests in both or either one location.
- `tox -e tracecontext` to run integration tests for tracecontext.

`ruff check` and `ruff format` are executed when `tox -e ruff` is run. We strongly recommend you to configure [pre-commit](https://pre-commit.com/) locally to run `ruff` automatically before each commit by installing it as git hooks. You just need to [install pre-commit](https://pre-commit.com/#install) in your environment:

Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pylint==3.2.1
httpretty==1.1.4
pyright==1.1.396
mypy==1.9.0
sphinx==7.1.2
sphinx-rtd-theme==2.0.0rc4
Expand Down
1 change: 0 additions & 1 deletion mypy-requirements.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def create_gauge( # type: ignore # pylint: disable=no-self-use
name: str,
unit: str = "",
description: str = "",
) -> Gauge:
) -> Gauge: # pyright: ignore [reportReturnType]
"""Creates a ``Gauge`` instrument

Args:
Expand Down
8 changes: 4 additions & 4 deletions opentelemetry-api/src/opentelemetry/util/_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ def __enter__(self) -> R:
except StopIteration:
raise RuntimeError("generator didn't yield") from None

def __call__(self, func: V) -> V:
def __call__(self, func: V) -> V: # pyright: ignore [reportIncompatibleMethodOverride]
if asyncio.iscoroutinefunction(func):

@functools.wraps(func) # type: ignore
async def async_wrapper(*args: Pargs, **kwargs: Pkwargs) -> R:
async def async_wrapper(*args: Pargs, **kwargs: Pkwargs) -> R: # pyright: ignore [reportInvalidTypeVarUse]
with self._recreate_cm(): # type: ignore
return await func(*args, **kwargs) # type: ignore

Expand All @@ -78,8 +78,8 @@ def _agnosticcontextmanager(
func: "Callable[P, Iterator[R]]",
) -> "Callable[P, _AgnosticContextManager[R]]":
@functools.wraps(func)
def helper(*args: Pargs, **kwargs: Pkwargs) -> _AgnosticContextManager[R]:
return _AgnosticContextManager(func, args, kwargs)
def helper(*args: Pargs, **kwargs: Pkwargs) -> _AgnosticContextManager[R]: # pyright: ignore [reportInvalidTypeVarUse]
return _AgnosticContextManager(func, args, kwargs) # pyright: ignore [reportArgumentType]

# Ignoring the type to keep the original signature of the function
return helper # type: ignore[return-value]
5 changes: 3 additions & 2 deletions opentelemetry-api/tests/trace/test_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ class TestUseSpanException(Exception):
raise TestUseSpanException("test error")

self.assertEqual(
test_span.recorded_status.status_code, StatusCode.ERROR
test_span.recorded_status.status_code, # pyright: ignore [reportAttributeAccessIssue]
StatusCode.ERROR,
)
self.assertEqual(
test_span.recorded_status.description,
test_span.recorded_status.description, # pyright: ignore [reportAttributeAccessIssue]
"TestUseSpanException: test error",
)
6 changes: 3 additions & 3 deletions opentelemetry-api/tests/util/test_once.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ def test_once_single_thread(self):
self.assertEqual(once_func.call_count, 0)

# first call should run
called = once.do_once(once_func)
called = once.do_once(once_func) # pyright: ignore [reportArgumentType]
self.assertTrue(called)
self.assertEqual(once_func.call_count, 1)

# subsequent calls do nothing
called = once.do_once(once_func)
called = once.do_once(once_func) # pyright: ignore [reportArgumentType]
self.assertFalse(called)
self.assertEqual(once_func.call_count, 1)

Expand All @@ -38,7 +38,7 @@ def test_once_many_threads(self):
once = Once()

def run_concurrently() -> bool:
return once.do_once(once_func)
return once.do_once(once_func) # pyright: ignore [reportArgumentType]

results = self.run_with_many_threads(run_concurrently, num_threads=100)

Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/tests/metrics/test_backward_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
and PeriodicExportingMetricReader concrete class. Those may freely be modified in a
backward-compatible way for *callers*.

Ideally, we could use mypy for this as well, but SDK is not type checked atm.
Ideally, we could use pyright for this as well, but SDK is not type checked atm.
"""

from typing import Iterable, Sequence
Expand Down
24 changes: 15 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@
addopts = "-rs -v"
log_cli = true

[tool.pyright]
typeCheckingMode = "off"
reportMissingTypeStubs = "error"
include = [
"opentelemetry-api/src",
"opentelemetry-sdk/src",
"opentelemetry-semantic-conventions/src",
]

[tool.ruff]
# https://docs.astral.sh/ruff/configuration/
target-version = "py38"
Expand Down Expand Up @@ -49,3 +40,18 @@ known-third-party = [
"opencensus",
]
known-first-party = ["opentelemetry", "opentelemetry_example_app"]

[tool.pyright]
typeCheckingMode = "standard"
pythonVersion = "3.8"
reportPrivateUsage = false

include = [
"opentelemetry-semantic-conventions",
"opentelemetry-api",
]

# When packages are correct typed add them to the strict list
strict = [
"opentelemetry-semantic-conventions",
]
1 change: 0 additions & 1 deletion pyright-requirements.txt

This file was deleted.

19 changes: 11 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ envlist =
spellcheck
tracecontext
mypy,mypyinstalled
pyright
typecheck
docs
docker-tests-{otlpexporter,opencensus}
public-symbols-check
Expand All @@ -103,7 +103,8 @@ deps =
coverage: pytest
coverage: pytest-cov

mypy,mypyinstalled: -r {toxinidir}/mypy-requirements.txt
mypy,mypyinstalled: -c {toxinidir}/dev-requirements.txt
mypy,mypyinstalled: mypy

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

Expand Down Expand Up @@ -161,7 +162,6 @@ setenv =
CONTRIB_REPO_SHA={env:CONTRIB_REPO_SHA:main}
CONTRIB_REPO=git+https://github.com/open-telemetry/opentelemetry-python-contrib.git@{env:CONTRIB_REPO_SHA}
mypy: MYPYPATH={toxinidir}/opentelemetry-api/src/:{toxinidir}/opentelemetry-semantic-conventions/src/:{toxinidir}/opentelemetry-sdk/src/:{toxinidir}/tests/opentelemetry-test-utils/src/

commands_pre =
; In order to get a healthy coverage report,
; we have to install packages in editable mode.
Expand Down Expand Up @@ -235,11 +235,11 @@ commands =
mypy: mypy --install-types --non-interactive --namespace-packages --explicit-package-bases opentelemetry-sdk/src/opentelemetry/sdk/resources
mypy: mypy --install-types --non-interactive --namespace-packages --explicit-package-bases opentelemetry-semantic-conventions/src/opentelemetry/semconv/

; For test code, we don't want to enforce the full mypy strictness
; For test code, we don't want to enforce the full mypy strictness
mypy: mypy --install-types --non-interactive --namespace-packages --config-file=mypy-relaxed.ini opentelemetry-api/tests/

; Test that mypy can pick up typeinfo from an installed package (otherwise,
; implicit Any due to unfollowed import would result).
; Test that mypy can pick up typeinfo from an installed package (otherwise,
; implicit Any due to unfollowed import would result).
mypyinstalled: mypy --install-types --non-interactive --namespace-packages opentelemetry-api/tests/mypysmoke.py --strict

[testenv:spellcheck]
Expand Down Expand Up @@ -347,13 +347,16 @@ commands_pre =
commands =
sh -c "find {toxinidir} -name \*.sh | xargs shellcheck --severity=warning"

[testenv:pyright]
[testenv:typecheck]
basepython: python3
deps =
-r {toxinidir}/pyright-requirements.txt
-c {toxinidir}/dev-requirements.txt
pyright
psutil
-e {toxinidir}/opentelemetry-api
-e {toxinidir}/opentelemetry-semantic-conventions
-e {toxinidir}/opentelemetry-sdk
-e {toxinidir}/tests/opentelemetry-test-utils
commands =
pyright --version
pyright
Expand Down
Loading