6767from json import dumps
6868from os import environ
6969from types import ModuleType
70- from typing import List , MutableMapping , Optional , cast
70+ from typing import List , Optional , cast
7171from urllib import parse
7272
7373from opentelemetry .attributes import BoundedAttributes
7777 OTEL_SERVICE_NAME ,
7878)
7979from opentelemetry .semconv .resource import ResourceAttributes
80- from opentelemetry .util ._importlib_metadata import entry_points , version
80+ from opentelemetry .util ._importlib_metadata import (
81+ entry_points , # type: ignore[reportUnknownVariableType]
82+ version ,
83+ )
8184from opentelemetry .util .types import AttributeValue
8285
8386psutil : Optional [ModuleType ] = None
@@ -210,7 +213,7 @@ def create(
210213 entry_points (
211214 group = "opentelemetry_resource_detector" ,
212215 name = resource_detector .strip (),
213- ) # type: ignore
216+ ) # type: ignore[reportUnknownArgumentType]
214217 )
215218 ).load ()()
216219 )
@@ -266,8 +269,8 @@ def merge(self, other: "Resource") -> "Resource":
266269 Returns:
267270 The newly-created Resource.
268271 """
269- merged_attributes = self .attributes .copy () # type: ignore
270- merged_attributes .update (other .attributes ) # type: ignore
272+ merged_attributes = dict ( self .attributes ) .copy ()
273+ merged_attributes .update (other .attributes )
271274
272275 if self .schema_url == "" :
273276 schema_url = other .schema_url
@@ -282,7 +285,7 @@ def merge(self, other: "Resource") -> "Resource":
282285 other .schema_url ,
283286 )
284287 return self
285- return Resource (merged_attributes , schema_url ) # type: ignore
288+ return Resource (merged_attributes , schema_url )
286289
287290 def __eq__ (self , other : object ) -> bool :
288291 if not isinstance (other , Resource ):
@@ -294,16 +297,13 @@ def __eq__(self, other: object) -> bool:
294297
295298 def __hash__ (self ) -> int :
296299 return hash (
297- f"{ dumps (self ._attributes .copy (), sort_keys = True )} |{ self ._schema_url } " # type: ignore
300+ f"{ dumps (self ._attributes .copy (), sort_keys = True )} |{ self ._schema_url } "
298301 )
299302
300303 def to_json (self , indent : Optional [int ] = 4 ) -> str :
301- attributes : MutableMapping [str , AttributeValue ] = dict (
302- self ._attributes
303- )
304304 return dumps (
305305 {
306- "attributes" : attributes , # type: ignore
306+ "attributes" : dict ( self . _attributes ),
307307 "schema_url" : self ._schema_url ,
308308 },
309309 indent = indent ,
@@ -334,7 +334,7 @@ class OTELResourceDetector(ResourceDetector):
334334 # pylint: disable=no-self-use
335335 def detect (self ) -> "Resource" :
336336 env_resources_items = environ .get (OTEL_RESOURCE_ATTRIBUTES )
337- env_resource_map = {}
337+ env_resource_map : dict [ str , AttributeValue ] = {}
338338
339339 if env_resources_items :
340340 for item in env_resources_items .split ("," ):
@@ -392,7 +392,7 @@ def detect(self) -> "Resource":
392392 resource_info [PROCESS_PARENT_PID ] = os .getppid ()
393393
394394 if psutil is not None :
395- process : psutil_module . Process = psutil .Process ()
395+ process = psutil .Process ()
396396 username = process .username ()
397397 resource_info [PROCESS_OWNER ] = username
398398
@@ -483,7 +483,7 @@ def detect(self) -> "Resource":
483483 )
484484
485485
486- class _HostResourceDetector (ResourceDetector ):
486+ class _HostResourceDetector (ResourceDetector ): # type: ignore[reportUnusedClass]
487487 """
488488 The HostResourceDetector detects the hostname and architecture attributes.
489489 """
0 commit comments