prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Add type annontations
  please add type annotations here
  
  _Originally posted by @aabmass in https://github.com/open-telemetry/opentelemetry-python/pull/2400#discussion_r809406486_
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `opentelemetry-sdk/src/opentelemetry/sdk/_metrics/_view_instrument_match.py`
  Content:
  ```
  1 # Copyright The OpenTelemetry Authors
  2 #
  3 # Licensed under the Apache License, Version 2.0 (the "License");
  4 # you may not use this file except in compliance with the License.
  5 # You may obtain a copy of the License at
  6 #
  7 #     http://www.apache.org/licenses/LICENSE-2.0
  8 #
  9 # Unless required by applicable law or agreed to in writing, software
  10 # distributed under the License is distributed on an "AS IS" BASIS,
  11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12 # See the License for the specific language governing permissions and
  13 # limitations under the License.
  14 
  15 
  16 from logging import getLogger
  17 from threading import Lock
  18 from typing import TYPE_CHECKING, Iterable
  19 
  20 from opentelemetry.sdk._metrics.aggregation import (
  21     _convert_aggregation_temporality,
  22 )
  23 from opentelemetry.sdk._metrics.measurement import Measurement
  24 from opentelemetry.sdk._metrics.point import AggregationTemporality, Metric
  25 from opentelemetry.sdk._metrics.sdk_configuration import SdkConfiguration
  26 from opentelemetry.sdk._metrics.view import View
  27 
  28 if TYPE_CHECKING:
  29     from opentelemetry.sdk._metrics.instrument import _Instrument
  30 
  31 _logger = getLogger(__name__)
  32 
  33 
  34 class _ViewInstrumentMatch:
  35     def __init__(
  36         self,
  37         view: View,
  38         instrument: "_Instrument",
  39         sdk_config: SdkConfiguration,
  40     ):
  41         self._view = view
  42         self._instrument = instrument
  43         self._sdk_config = sdk_config
  44         self._attributes_aggregation = {}
  45         self._attributes_previous_point = {}
  46         self._lock = Lock()
  47 
  48     # pylint: disable=protected-access
  49     def consume_measurement(self, measurement: Measurement) -> None:
  50 
  51         if self._view._attribute_keys is not None:
  52 
  53             attributes = {}
  54 
  55             for key, value in (measurement.attributes or {}).items():
  56                 if key in self._view._attribute_keys:
  57                     attributes[key] = value
  58         elif measurement.attributes is not None:
  59             attributes = measurement.attributes
  60         else:
  61             attributes = {}
  62 
  63         attributes = frozenset(attributes.items())
  64 
  65         if attributes not in self._attributes_aggregation:
  66             with self._lock:
  67                 if attributes not in self._attributes_aggregation:
  68                     if self._view._aggregation:
  69                         aggregation = (
  70                             self._view._aggregation._create_aggregation(
  71                                 self._instrument
  72                             )
  73                         )
  74                     else:
  75                         aggregation = self._instrument._default_aggregation
  76                     self._attributes_aggregation[attributes] = aggregation
  77 
  78         self._attributes_aggregation[attributes].aggregate(measurement)
  79 
  80     def collect(self, temporality: int) -> Iterable[Metric]:
  81 
  82         with self._lock:
  83             for (
  84                 attributes,
  85                 aggregation,
  86             ) in self._attributes_aggregation.items():
  87 
  88                 previous_point = self._attributes_previous_point.get(
  89                     attributes
  90                 )
  91 
  92                 current_point = aggregation.collect()
  93 
  94                 # pylint: disable=assignment-from-none
  95                 self._attributes_previous_point[
  96                     attributes
  97                 ] = _convert_aggregation_temporality(
  98                     previous_point,
  99                     current_point,
  100                     AggregationTemporality.CUMULATIVE,
  101                 )
  102 
  103                 if current_point is not None:
  104 
  105                     yield Metric(
  106                         attributes=dict(attributes),
  107                         description=(
  108                             self._view._description
  109                             or self._instrument.description
  110                         ),
  111                         instrumentation_info=self._instrument.instrumentation_info,
  112                         name=self._view._name or self._instrument.name,
  113                         resource=self._sdk_config.resource,
  114                         unit=self._instrument.unit,
  115                         point=_convert_aggregation_temporality(
  116                             previous_point,
  117                             current_point,
  118                             temporality,
  119                         ),
  120                     )
  121
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/_view_instrument_match.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/_view_instrument_match.py
  --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/_view_instrument_match.py
  +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/_view_instrument_match.py
  @@ -15,10 +15,12 @@
   
   from logging import getLogger
   from threading import Lock
  -from typing import TYPE_CHECKING, Iterable
  +from typing import TYPE_CHECKING, Dict, Iterable
   
   from opentelemetry.sdk._metrics.aggregation import (
  +    _Aggregation,
       _convert_aggregation_temporality,
  +    _PointVarT,
   )
   from opentelemetry.sdk._metrics.measurement import Measurement
   from opentelemetry.sdk._metrics.point import AggregationTemporality, Metric
  @@ -41,8 +43,8 @@
           self._view = view
           self._instrument = instrument
           self._sdk_config = sdk_config
  -        self._attributes_aggregation = {}
  -        self._attributes_previous_point = {}
  +        self._attributes_aggregation: Dict[frozenset, _Aggregation] = {}
  +        self._attributes_previous_point: Dict[frozenset, _PointVarT] = {}
           self._lock = Lock()
   
       # pylint: disable=protected-access
  
verification_info: {"golden_diff": "diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/_view_instrument_match.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/_view_instrument_match.py\n--- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/_view_instrument_match.py\n+++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/_view_instrument_match.py\n@@ -15,10 +15,12 @@\n \n from logging import getLogger\n from threading import Lock\n-from typing import TYPE_CHECKING, Iterable\n+from typing import TYPE_CHECKING, Dict, Iterable\n \n from opentelemetry.sdk._metrics.aggregation import (\n+    _Aggregation,\n     _convert_aggregation_temporality,\n+    _PointVarT,\n )\n from opentelemetry.sdk._metrics.measurement import Measurement\n from opentelemetry.sdk._metrics.point import AggregationTemporality, Metric\n@@ -41,8 +43,8 @@\n         self._view = view\n         self._instrument = instrument\n         self._sdk_config = sdk_config\n-        self._attributes_aggregation = {}\n-        self._attributes_previous_point = {}\n+        self._attributes_aggregation: Dict[frozenset, _Aggregation] = {}\n+        self._attributes_previous_point: Dict[frozenset, _PointVarT] = {}\n         self._lock = Lock()\n \n     # pylint: disable=protected-access\n", "issue": "Add type annontations\nplease add type annotations here\r\n\r\n_Originally posted by @aabmass in https://github.com/open-telemetry/opentelemetry-python/pull/2400#discussion_r809406486_\n", "before_files": [{"content": "# Copyright The OpenTelemetry Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\nfrom logging import getLogger\nfrom threading import Lock\nfrom typing import TYPE_CHECKING, Iterable\n\nfrom opentelemetry.sdk._metrics.aggregation import (\n    _convert_aggregation_temporality,\n)\nfrom opentelemetry.sdk._metrics.measurement import Measurement\nfrom opentelemetry.sdk._metrics.point import AggregationTemporality, Metric\nfrom opentelemetry.sdk._metrics.sdk_configuration import SdkConfiguration\nfrom opentelemetry.sdk._metrics.view import View\n\nif TYPE_CHECKING:\n    from opentelemetry.sdk._metrics.instrument import _Instrument\n\n_logger = getLogger(__name__)\n\n\nclass _ViewInstrumentMatch:\n    def __init__(\n        self,\n        view: View,\n        instrument: \"_Instrument\",\n        sdk_config: SdkConfiguration,\n    ):\n        self._view = view\n        self._instrument = instrument\n        self._sdk_config = sdk_config\n        self._attributes_aggregation = {}\n        self._attributes_previous_point = {}\n        self._lock = Lock()\n\n    # pylint: disable=protected-access\n    def consume_measurement(self, measurement: Measurement) -> None:\n\n        if self._view._attribute_keys is not None:\n\n            attributes = {}\n\n            for key, value in (measurement.attributes or {}).items():\n                if key in self._view._attribute_keys:\n                    attributes[key] = value\n        elif measurement.attributes is not None:\n            attributes = measurement.attributes\n        else:\n            attributes = {}\n\n        attributes = frozenset(attributes.items())\n\n        if attributes not in self._attributes_aggregation:\n            with self._lock:\n                if attributes not in self._attributes_aggregation:\n                    if self._view._aggregation:\n                        aggregation = (\n                            self._view._aggregation._create_aggregation(\n                                self._instrument\n                            )\n                        )\n                    else:\n                        aggregation = self._instrument._default_aggregation\n                    self._attributes_aggregation[attributes] = aggregation\n\n        self._attributes_aggregation[attributes].aggregate(measurement)\n\n    def collect(self, temporality: int) -> Iterable[Metric]:\n\n        with self._lock:\n            for (\n                attributes,\n                aggregation,\n            ) in self._attributes_aggregation.items():\n\n                previous_point = self._attributes_previous_point.get(\n                    attributes\n                )\n\n                current_point = aggregation.collect()\n\n                # pylint: disable=assignment-from-none\n                self._attributes_previous_point[\n                    attributes\n                ] = _convert_aggregation_temporality(\n                    previous_point,\n                    current_point,\n                    AggregationTemporality.CUMULATIVE,\n                )\n\n                if current_point is not None:\n\n                    yield Metric(\n                        attributes=dict(attributes),\n                        description=(\n                            self._view._description\n                            or self._instrument.description\n                        ),\n                        instrumentation_info=self._instrument.instrumentation_info,\n                        name=self._view._name or self._instrument.name,\n                        resource=self._sdk_config.resource,\n                        unit=self._instrument.unit,\n                        point=_convert_aggregation_temporality(\n                            previous_point,\n                            current_point,\n                            temporality,\n                        ),\n                    )\n", "path": "opentelemetry-sdk/src/opentelemetry/sdk/_metrics/_view_instrument_match.py"}], "after_files": [{"content": "# Copyright The OpenTelemetry Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\nfrom logging import getLogger\nfrom threading import Lock\nfrom typing import TYPE_CHECKING, Dict, Iterable\n\nfrom opentelemetry.sdk._metrics.aggregation import (\n    _Aggregation,\n    _convert_aggregation_temporality,\n    _PointVarT,\n)\nfrom opentelemetry.sdk._metrics.measurement import Measurement\nfrom opentelemetry.sdk._metrics.point import AggregationTemporality, Metric\nfrom opentelemetry.sdk._metrics.sdk_configuration import SdkConfiguration\nfrom opentelemetry.sdk._metrics.view import View\n\nif TYPE_CHECKING:\n    from opentelemetry.sdk._metrics.instrument import _Instrument\n\n_logger = getLogger(__name__)\n\n\nclass _ViewInstrumentMatch:\n    def __init__(\n        self,\n        view: View,\n        instrument: \"_Instrument\",\n        sdk_config: SdkConfiguration,\n    ):\n        self._view = view\n        self._instrument = instrument\n        self._sdk_config = sdk_config\n        self._attributes_aggregation: Dict[frozenset, _Aggregation] = {}\n        self._attributes_previous_point: Dict[frozenset, _PointVarT] = {}\n        self._lock = Lock()\n\n    # pylint: disable=protected-access\n    def consume_measurement(self, measurement: Measurement) -> None:\n\n        if self._view._attribute_keys is not None:\n\n            attributes = {}\n\n            for key, value in (measurement.attributes or {}).items():\n                if key in self._view._attribute_keys:\n                    attributes[key] = value\n        elif measurement.attributes is not None:\n            attributes = measurement.attributes\n        else:\n            attributes = {}\n\n        attributes = frozenset(attributes.items())\n\n        if attributes not in self._attributes_aggregation:\n            with self._lock:\n                if attributes not in self._attributes_aggregation:\n                    if self._view._aggregation:\n                        aggregation = (\n                            self._view._aggregation._create_aggregation(\n                                self._instrument\n                            )\n                        )\n                    else:\n                        aggregation = self._instrument._default_aggregation\n                    self._attributes_aggregation[attributes] = aggregation\n\n        self._attributes_aggregation[attributes].aggregate(measurement)\n\n    def collect(self, temporality: int) -> Iterable[Metric]:\n\n        with self._lock:\n            for (\n                attributes,\n                aggregation,\n            ) in self._attributes_aggregation.items():\n\n                previous_point = self._attributes_previous_point.get(\n                    attributes\n                )\n\n                current_point = aggregation.collect()\n\n                # pylint: disable=assignment-from-none\n                self._attributes_previous_point[\n                    attributes\n                ] = _convert_aggregation_temporality(\n                    previous_point,\n                    current_point,\n                    AggregationTemporality.CUMULATIVE,\n                )\n\n                if current_point is not None:\n\n                    yield Metric(\n                        attributes=dict(attributes),\n                        description=(\n                            self._view._description\n                            or self._instrument.description\n                        ),\n                        instrumentation_info=self._instrument.instrumentation_info,\n                        name=self._view._name or self._instrument.name,\n                        resource=self._sdk_config.resource,\n                        unit=self._instrument.unit,\n                        point=_convert_aggregation_temporality(\n                            previous_point,\n                            current_point,\n                            temporality,\n                        ),\n                    )\n", "path": "opentelemetry-sdk/src/opentelemetry/sdk/_metrics/_view_instrument_match.py"}]}