diff --git a/.github/workflows/misc_0.yml b/.github/workflows/misc_0.yml index 1497bbe8c45..3fb9266cc02 100644 --- a/.github/workflows/misc_0.yml +++ b/.github/workflows/misc_0.yml @@ -66,44 +66,6 @@ jobs: - name: Run tests run: tox -e tracecontext - mypy: - name: mypy - runs-on: ubuntu-latest - timeout-minutes: 30 - steps: - - name: Checkout repo @ SHA - ${{ github.sha }} - uses: actions/checkout@v4 - - - name: Set up Python 3.11 - uses: actions/setup-python@v5 - with: - python-version: "3.11" - - - name: Install tox - run: pip install tox - - - name: Run tests - run: tox -e mypy - - mypyinstalled: - name: mypyinstalled - runs-on: ubuntu-latest - timeout-minutes: 30 - steps: - - name: Checkout repo @ SHA - ${{ github.sha }} - uses: actions/checkout@v4 - - - name: Set up Python 3.11 - uses: actions/setup-python@v5 - with: - python-version: "3.11" - - - name: Install tox - run: pip install tox - - - name: Run tests - run: tox -e mypyinstalled - typecheck: name: typecheck runs-on: ubuntu-latest diff --git a/CHANGELOG.md b/CHANGELOG.md index 85ab5a84852..bac47c6bc01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +- typecheck: add sdk/resources and drop mypy + ([#4578](https://github.com/open-telemetry/opentelemetry-python/pull/4578)) - Refactor `BatchLogRecordProcessor` to simplify code and make the control flow more clear ([#4562](https://github.com/open-telemetry/opentelemetry-python/pull/4562/) and [#4535](https://github.com/open-telemetry/opentelemetry-python/pull/4535)). - ## Version 1.33.0/0.54b0 (2025-05-09) - Fix intermittent `Connection aborted` error when using otlp/http exporters diff --git a/dev-requirements.txt b/dev-requirements.txt index a2a55bc88b0..cd203a12104 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,7 +1,6 @@ pylint==3.3.4 httpretty==1.1.4 pyright==1.1.396 -mypy==1.9.0 sphinx==7.1.2 sphinx-rtd-theme==2.0.0rc4 sphinx-autodoc-typehints==1.25.2 diff --git a/mypy-relaxed.ini b/mypy-relaxed.ini deleted file mode 100644 index 34538bdd797..00000000000 --- a/mypy-relaxed.ini +++ /dev/null @@ -1,22 +0,0 @@ -; This is mainly intended for unit tests and such. So probably 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 deleted file mode 100644 index 4c368fcd944..00000000000 --- a/mypy.ini +++ /dev/null @@ -1,22 +0,0 @@ -[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 - warn_unused_configs = True - warn_unused_ignores = True - warn_return_any = True - warn_redundant_casts = True - strict_equality = True - strict_optional = True - no_implicit_optional = True - no_implicit_reexport = True - # https://mypy.readthedocs.io/en/stable/running_mypy.html#follow-imports - follow_imports = silent diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py index 752b9067b77..9038d51334d 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py @@ -67,7 +67,7 @@ from json import dumps from os import environ from types import ModuleType -from typing import List, MutableMapping, Optional, cast +from typing import List, Optional, cast from urllib import parse from opentelemetry.attributes import BoundedAttributes @@ -77,7 +77,10 @@ OTEL_SERVICE_NAME, ) from opentelemetry.semconv.resource import ResourceAttributes -from opentelemetry.util._importlib_metadata import entry_points, version +from opentelemetry.util._importlib_metadata import ( + entry_points, # type: ignore[reportUnknownVariableType] + version, +) from opentelemetry.util.types import AttributeValue psutil: Optional[ModuleType] = None @@ -210,7 +213,7 @@ def create( entry_points( group="opentelemetry_resource_detector", name=resource_detector.strip(), - ) # type: ignore + ) # type: ignore[reportUnknownArgumentType] ) ).load()() ) @@ -266,8 +269,8 @@ def merge(self, other: "Resource") -> "Resource": Returns: The newly-created Resource. """ - merged_attributes = self.attributes.copy() # type: ignore - merged_attributes.update(other.attributes) # type: ignore + merged_attributes = dict(self.attributes).copy() + merged_attributes.update(other.attributes) if self.schema_url == "": schema_url = other.schema_url @@ -282,7 +285,7 @@ def merge(self, other: "Resource") -> "Resource": other.schema_url, ) return self - return Resource(merged_attributes, schema_url) # type: ignore + return Resource(merged_attributes, schema_url) def __eq__(self, other: object) -> bool: if not isinstance(other, Resource): @@ -294,16 +297,13 @@ def __eq__(self, other: object) -> bool: def __hash__(self) -> int: return hash( - f"{dumps(self._attributes.copy(), sort_keys=True)}|{self._schema_url}" # type: ignore + f"{dumps(self._attributes.copy(), sort_keys=True)}|{self._schema_url}" ) def to_json(self, indent: Optional[int] = 4) -> str: - attributes: MutableMapping[str, AttributeValue] = dict( - self._attributes - ) return dumps( { - "attributes": attributes, # type: ignore + "attributes": dict(self.attributes), "schema_url": self._schema_url, }, indent=indent, @@ -334,7 +334,7 @@ class OTELResourceDetector(ResourceDetector): # pylint: disable=no-self-use def detect(self) -> "Resource": env_resources_items = environ.get(OTEL_RESOURCE_ATTRIBUTES) - env_resource_map = {} + env_resource_map: dict[str, AttributeValue] = {} if env_resources_items: for item in env_resources_items.split(","): @@ -392,7 +392,7 @@ def detect(self) -> "Resource": resource_info[PROCESS_PARENT_PID] = os.getppid() if psutil is not None: - process: psutil_module.Process = psutil.Process() + process = psutil.Process() username = process.username() resource_info[PROCESS_OWNER] = username @@ -483,7 +483,7 @@ def detect(self) -> "Resource": ) -class _HostResourceDetector(ResourceDetector): +class _HostResourceDetector(ResourceDetector): # type: ignore[reportUnusedClass] """ The HostResourceDetector detects the hostname and architecture attributes. """ diff --git a/pyproject.toml b/pyproject.toml index ba590c2758e..8879064e7c4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -113,7 +113,6 @@ exclude = [ "opentelemetry-sdk/src/opentelemetry/sdk/_events", "opentelemetry-sdk/src/opentelemetry/sdk/_logs", "opentelemetry-sdk/src/opentelemetry/sdk/error_handler", - "opentelemetry-sdk/src/opentelemetry/sdk/resources", "opentelemetry-sdk/src/opentelemetry/sdk/metrics", "opentelemetry-sdk/src/opentelemetry/sdk/trace", "opentelemetry-sdk/src/opentelemetry/sdk/util", @@ -124,4 +123,5 @@ exclude = [ strict = [ "opentelemetry-semantic-conventions", "opentelemetry-sdk/src/opentelemetry/sdk/environment_variables", + "opentelemetry-sdk/src/opentelemetry/sdk/resources", ] diff --git a/tox.ini b/tox.ini index 83b8fc2dce0..72cf9f4feae 100644 --- a/tox.ini +++ b/tox.ini @@ -88,7 +88,6 @@ envlist = spellcheck tracecontext - mypy,mypyinstalled typecheck docs docker-tests-{otlpexporter,opencensus} @@ -103,9 +102,6 @@ deps = coverage: pytest coverage: pytest-cov - mypy,mypyinstalled: -c {toxinidir}/dev-requirements.txt - mypy,mypyinstalled: mypy - api: -r {toxinidir}/opentelemetry-api/test-requirements.txt sdk: -r {toxinidir}/opentelemetry-sdk/test-requirements.txt @@ -145,7 +141,6 @@ deps = propagator-jaeger: -r {toxinidir}/propagator/opentelemetry-propagator-jaeger/test-requirements.txt - mypyinstalled: -e {toxinidir}/opentelemetry-api getting-started: -r {toxinidir}/docs/getting_started/tests/requirements.txt getting-started: {env:CONTRIB_REPO}\#egg=opentelemetry-util-http&subdirectory=util/opentelemetry-util-http @@ -161,7 +156,6 @@ setenv = ; i.e: CONTRIB_REPO_SHA=dde62cebffe519c35875af6d06fae053b3be65ec tox -e 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. @@ -230,18 +224,6 @@ commands = coverage: {toxinidir}/scripts/coverage.sh - mypy: mypy --version - mypy: mypy --install-types --non-interactive --namespace-packages --explicit-package-bases opentelemetry-api/src/opentelemetry/ - 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 - 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). - mypyinstalled: mypy --install-types --non-interactive --namespace-packages opentelemetry-api/tests/mypysmoke.py --strict - [testenv:spellcheck] basepython: python3 recreate = True