From fd3be67896f1d46f1c9fa82e81a7994ade76d538 Mon Sep 17 00:00:00 2001 From: Liudmila Molkova Date: Tue, 20 Feb 2024 14:50:36 -0800 Subject: [PATCH] mypy --- semantic-conventions/dev-requirements.txt | 3 +-- semantic-conventions/mypy.ini | 4 ++++ semantic-conventions/setup.cfg | 1 + .../src/opentelemetry/semconv/main.py | 14 ++++++----- .../semconv/templating/compatibility.py | 24 ++++++++++++------- .../semconv/templating/test_compatibility.py | 1 + 6 files changed, 30 insertions(+), 17 deletions(-) diff --git a/semantic-conventions/dev-requirements.txt b/semantic-conventions/dev-requirements.txt index d3eb9ab1..6ec71734 100644 --- a/semantic-conventions/dev-requirements.txt +++ b/semantic-conventions/dev-requirements.txt @@ -3,5 +3,4 @@ mypy==0.910 pytest==8.0.1 flake8==7.0.0 pylint==3.0.3 -isort==5.13.2 -requests==2.31.0 \ No newline at end of file +isort==5.13.2 \ No newline at end of file diff --git a/semantic-conventions/mypy.ini b/semantic-conventions/mypy.ini index 9ecdc1d5..a8dff7d7 100644 --- a/semantic-conventions/mypy.ini +++ b/semantic-conventions/mypy.ini @@ -5,3 +5,7 @@ ignore_missing_imports = True [mypy-mistune.*] ignore_missing_imports = True + +[mypy-requests.*] +ignore_missing_imports = True + diff --git a/semantic-conventions/setup.cfg b/semantic-conventions/setup.cfg index ce15e71c..0d1cc511 100644 --- a/semantic-conventions/setup.cfg +++ b/semantic-conventions/setup.cfg @@ -40,6 +40,7 @@ install_requires = ruamel.yaml~=0.16 Jinja2~=3.0 mistune==2.0.0a6 + requests==2.31.0 [options.packages.find] where = src diff --git a/semantic-conventions/src/opentelemetry/semconv/main.py b/semantic-conventions/src/opentelemetry/semconv/main.py index c1ed9f03..7e923cb6 100644 --- a/semantic-conventions/src/opentelemetry/semconv/main.py +++ b/semantic-conventions/src/opentelemetry/semconv/main.py @@ -120,13 +120,14 @@ def check_compatibility(semconv, args, parser): def find_yaml(yaml_root: str, exclude: str) -> List[str]: - if yaml_root is not None: - exclude = set(exclude_file_list(yaml_root if yaml_root else "", exclude)) + excluded_files = set(exclude_file_list(yaml_root if yaml_root else "", exclude)) yaml_files = set(glob.glob(f"{yaml_root}/**/*.yaml", recursive=True)).union( set(glob.glob(f"{yaml_root}/**/*.yml", recursive=True)) ) - return yaml_files - exclude + return yaml_files - excluded_files + + return [] def check_args(arguments, parser): @@ -137,7 +138,7 @@ def check_args(arguments, parser): def parse_only_filter(only: str, parser) -> List[str]: if not only: - return None + return [] types = [t.strip() for t in only.split(",")] unknown_types = [t for t in types if t not in CONVENTION_CLS_BY_GROUP_TYPE.keys()] @@ -321,8 +322,9 @@ def download_previous_version(version: str) -> str: f"https://github.com/open-telemetry/semantic-conventions/archive/{filename}" ) - request = requests.get(semconv_vprev, allow_redirects=True) - open(path_to_zip, "wb").write(request.content) + request = requests.get(semconv_vprev, allow_redirects=True, timeout=30) + with open(path_to_zip, "wb") as zip_file: + zip_file.write(request.content) with zipfile.ZipFile(path_to_zip, "r") as zip_ref: zip_ref.extractall(path_to_semconv) diff --git a/semantic-conventions/src/opentelemetry/semconv/templating/compatibility.py b/semantic-conventions/src/opentelemetry/semconv/templating/compatibility.py index a2ab6a61..f5ea0bb3 100644 --- a/semantic-conventions/src/opentelemetry/semconv/templating/compatibility.py +++ b/semantic-conventions/src/opentelemetry/semconv/templating/compatibility.py @@ -1,4 +1,5 @@ from opentelemetry.semconv.model.semantic_attribute import ( + EnumAttributeType, EnumMember, RequirementLevel, SemanticAttribute, @@ -20,6 +21,7 @@ def __init__(self, signal: str, name: str, message: str, critical: bool = True): self.signal = signal self.name = name self.message = message + self.critical = critical def __str__(self): return f"\t {self.signal} '{self.name}': {self.message}" @@ -27,8 +29,8 @@ def __str__(self): def __eq__(self, other): if isinstance(other, self.__class__): return self.__dict__ == other.__dict__ - else: - return False + + return False def __ne__(self, other): return not self.__eq__(other) @@ -46,7 +48,7 @@ def __init__( self.previous_semconv = previous_semconv def check(self) -> list[Problem]: - problems = [] + problems = [] # type: list[Problem] for semconv in self.previous_semconv.models.values(): for prev_attr in semconv.attributes_and_templates: if ( @@ -59,7 +61,7 @@ def check(self) -> list[Problem]: self._check_metric(semconv, problems) return problems - def _check_attribute(self, prev: SemanticAttribute, problems: list[str]): + def _check_attribute(self, prev: SemanticAttribute, problems: list[Problem]): cur = self.current_semconv._lookup_attribute(prev.fqn) if cur is None: problems.append(Problem("attribute", prev.fqn, "was removed")) @@ -75,8 +77,8 @@ def _check_attribute(self, prev: SemanticAttribute, problems: list[str]): ) ) - if prev.is_enum: - if not cur.is_enum: + if isinstance(prev.attr_type, EnumAttributeType): + if not isinstance(cur.attr_type, EnumAttributeType): problems.append( Problem( "attribute", @@ -107,7 +109,11 @@ def _check_attribute(self, prev: SemanticAttribute, problems: list[str]): ) def _check_member( - self, fqn: str, prev: EnumMember, members: list[EnumMember], problems: list[str] + self, + fqn: str, + prev: EnumMember, + members: list[EnumMember], + problems: list[Problem], ): for member in members: if prev.value == member.value: @@ -119,7 +125,7 @@ def _check_member( ) ) - def _check_metric(self, prev: MetricSemanticConvention, problems: list[str]): + def _check_metric(self, prev: MetricSemanticConvention, problems: list[Problem]): for cur in self.current_semconv.models.values(): if ( isinstance(cur, MetricSemanticConvention) @@ -159,7 +165,7 @@ def _check_metric_attributes( self, prev: MetricSemanticConvention, cur: MetricSemanticConvention, - problems: list[str], + problems: list[Problem], ): if prev.stability == StabilityLevel.STABLE: prev_default_attributes = [ diff --git a/semantic-conventions/src/tests/semconv/templating/test_compatibility.py b/semantic-conventions/src/tests/semconv/templating/test_compatibility.py index 11cd72d0..85f88fe1 100644 --- a/semantic-conventions/src/tests/semconv/templating/test_compatibility.py +++ b/semantic-conventions/src/tests/semconv/templating/test_compatibility.py @@ -108,6 +108,7 @@ def testMetricAttributeAdded(self): "metric", "metric_one", "attributes changed from '['first.first_attr']' to '['first.first_attr', 'first.second_attr']'", + critical=False, ) ] self.assert_errors(expected_errors, problems)