Skip to content

Commit

Permalink
mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
lmolkova committed Mar 15, 2024
1 parent 3be2549 commit a028686
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ def parse_stability(stability, position_data, attr_id, validation_ctx):

msg = f"Value '{stability}' is not allowed as a stability marker"
validation_ctx.raise_or_warn(position_data["stability"], msg, attr_id)
return None

@staticmethod
def parse_deprecated(deprecated, position_data, attr_id, validation_ctx):
Expand Down Expand Up @@ -442,6 +443,7 @@ def to_bool(key, parent_object, validation_ctx):
msg,
parent_object.get("id"),
)
return None


@dataclass
Expand Down Expand Up @@ -531,7 +533,7 @@ def parse(attribute_type, position, validation_ctx):
validation_ctx.raise_or_warn(
myaml.lc.data["value"],
f"Enumeration member does not have type {enum_type}!",
enum_type.get("id"),
m.member_id,
)
return EnumAttributeType(custom_values, members, enum_type)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def parse_semantic_convention_groups(yaml_file, validation_ctx):

def SemanticConvention(group, validation_ctx):
type_value = group.get("type")
id = group.get("id")
semconv_id = group.get("id")
if type_value is None:
line = group.lc.data["id"][0] + 1
doc_url = "https://github.com/open-telemetry/build-tools/blob/main/semantic-conventions/syntax.md#groups"
Expand All @@ -88,7 +88,7 @@ def SemanticConvention(group, validation_ctx):
if convention_type is None:
position = group.lc.data["type"] if "type" in group else group.lc.data["id"]
msg = f"Invalid value for semantic convention type: {group.get('type')}"
validation_ctx.raise_or_warn(position, msg, id)
validation_ctx.raise_or_warn(position, msg, semconv_id)

# First, validate that the correct fields are available in the yaml
convention_type.validate_keys(group, validation_ctx)
Expand Down Expand Up @@ -313,6 +313,7 @@ class SemanticConventionSet:
debug: bool
models: typing.Dict[str, BaseSemanticConvention] = field(default_factory=dict)
errors: bool = False
validation_ctx: ValidationContext = None

def parse(self, file, validation_ctx=None):
self.validation_ctx = validation_ctx or ValidationContext(file, True)
Expand Down Expand Up @@ -398,15 +399,15 @@ def _populate_extends_single(self, semconv, unprocessed):
Resolves the parent/child relationship for a single Semantic Convention. If the parent **p** of the input
semantic convention **i** has in turn a parent **pp**, it recursively resolves **pp** before processing **p**.
:param semconv: The semantic convention for which resolve the parent/child relationship.
:param semconvs: The list of remaining semantic conventions to process.
:param unprocessed: The list of remaining semantic conventions to process.
:return: A list of remaining semantic convention to process.
"""
# Resolve parent of current Semantic Convention
if semconv.extends:
extended = self.models.get(semconv.extends)
if extended is None:
self.validation_ctx.raise_or_warn(
self._position,
semconv._position,
f"Semantic Convention {semconv.semconv_id} extends "
f"{semconv.extends} but the latter cannot be found!",
semconv.semconv_id,
Expand Down
7 changes: 3 additions & 4 deletions semantic-conventions/src/opentelemetry/semconv/model/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ def validate_id(semconv_id, position, validation_ctx):

def validate_values(yaml, keys, validation_ctx, mandatory=()):
"""This method checks only valid keywords and value types are used"""
id = yaml.get("id")
node_id = yaml.get("id")
unwanted = [k for k in yaml.keys() if k not in keys]
if unwanted:
position = yaml.lc.data[unwanted[0]]
msg = f"Invalid keys: {unwanted}"
validation_ctx.raise_or_warn(position, msg, id)
validation_ctx.raise_or_warn(position, msg, node_id)
if mandatory:
check_no_missing_keys(yaml, mandatory, validation_ctx)

Expand Down Expand Up @@ -95,5 +95,4 @@ def raise_or_warn(self, pos, msg, fqn):
error = ValidationError(pos[0] + 1, pos[1] + 1, msg, fqn)
if self.strict_validation:
raise error
else:
print(f"[Warning] {self.file_name}: {error}\n")
print(f"[Warning] {self.file_name}: {error}\n")

0 comments on commit a028686

Please sign in to comment.