Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make pylint work with python 3.11 and fix new errors #125

Merged
merged 3 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion semantic-conventions/.pylintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[MESSAGES CONTROL]
# TODO: We should actually fix the warnings instead of disabling them
# except for the stuff up to fixme, which is fine to ignore / defer to black.
disable = bad-whitespace, wrong-import-order, wrong-hanging-indentation, line-too-long, missing-docstring, unused-import, fixme, invalid-name, too-many-instance-attributes, too-many-locals, too-many-statements, too-many-branches, too-many-arguments, too-many-public-methods, too-few-public-methods, protected-access
lmolkova marked this conversation as resolved.
Show resolved Hide resolved
disable = wrong-import-order, line-too-long, missing-docstring, unused-import, fixme, invalid-name, too-many-instance-attributes, too-many-locals, too-many-statements, too-many-branches, too-many-arguments, too-many-public-methods, too-few-public-methods, protected-access

[FORMAT]
good-names=e,ex
2 changes: 1 addition & 1 deletion semantic-conventions/dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ black==22.3.0
mypy==0.910
pytest==6.2.5
flake8==3.9.2
pylint==2.10.2
pylint==2.15.5
isort==5.9.3
6 changes: 3 additions & 3 deletions semantic-conventions/src/opentelemetry/semconv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def parse_semconv(args, parser) -> SemanticConventionSet:
find_yaml(args)
for file in sorted(args.files):
if not file.endswith(".yaml") and not file.endswith(".yml"):
parser.error("{} is not a yaml file.".format(file))
parser.error(f"{file} is not a yaml file.")
semconv.parse(file)
semconv.finish()
if semconv.has_error():
Expand Down Expand Up @@ -97,8 +97,8 @@ def find_yaml(args):
exclude_file_list(args.yaml_root if args.yaml_root else "", args.exclude)
)
yaml_files = set(
glob.glob("{}/**/*.yaml".format(args.yaml_root), recursive=True)
).union(set(glob.glob("{}/**/*.yml".format(args.yaml_root), recursive=True)))
glob.glob(f"{args.yaml_root}/**/*.yaml", recursive=True)
).union(set(glob.glob(f"{args.yaml_root}/**/*.yml", recursive=True)))
file_names = yaml_files - exclude
args.files.extend(file_names)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ def __init__(self, line, column, message):
self.column = column

def __str__(self):
return "{} - @{}:{}".format(self.message, self.line, self.column)
return f"{self.message} - @{self.line}:{self.column}"
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ def parse(
validate_id(attr_id, position_data["id"])
attr_type, brief, examples = SemanticAttribute.parse_id(attribute)
if prefix:
fqn = "{}.{}".format(prefix, attr_id)
fqn = f"{prefix}.{attr_id}"
else:
fqn = attr_id
else:
# Ref
attr_type = None
if "type" in attribute:
msg = "Ref attribute '{}' must not declare a type".format(ref)
msg = f"Ref attribute '{ref}' must not declare a type"
raise ValidationError.from_yaml_pos(position, msg)
brief = attribute.get("brief")
examples = attribute.get("examples")
Expand Down Expand Up @@ -164,8 +164,8 @@ def parse(

if requirement_level_val and requirement_level is None:
position = position_data["requirement_level"]
msg = "Value '{}' for required field is not allowed".format(
requirement_level_val
msg = (
f"Value '{requirement_level_val}' for required field is not allowed"
)
raise ValidationError.from_yaml_pos(position, msg)

Expand All @@ -190,9 +190,7 @@ def parse(
if "stability" in position_data
else position_data["deprecated"]
)
msg = "Semantic convention stability set to deprecated but attribute '{}' is {}".format(
attr_id, stability
)
msg = f"Semantic convention stability set to deprecated but attribute '{attr_id}' is {stability}"
raise ValidationError.from_yaml_pos(position, msg)
stability = stability or semconv_stability or StabilityLevel.STABLE
sampling_relevant = (
Expand Down Expand Up @@ -259,7 +257,7 @@ def parse_id(attribute):
and not isinstance(examples, CommentedSeq)
):
position = attribute.lc.data[list(attribute)[0]]
msg = "Non array examples for {} are not allowed".format(attr_type)
msg = f"Non array examples for {attr_type} are not allowed"
raise ValidationError.from_yaml_pos(position, msg)
if not isinstance(examples, CommentedSeq) and examples is not None:
# TODO: If validation fails later, this will crash when trying to access position data
Expand All @@ -275,7 +273,7 @@ def parse_id(attribute):
):
if not examples:
position = attribute.lc.data[list(attribute)[0]]
msg = "Empty examples for {} are not allowed".format(attr_type)
msg = f"Empty examples for {attr_type} are not allowed"
raise ValidationError.from_yaml_pos(position, msg)

# TODO: Implement type check for enum examples or forbid them
Expand All @@ -290,9 +288,7 @@ def parse_stability_deprecated(stability, deprecated, position_data):
if deprecated is not None:
if stability is not None and stability != "deprecated":
position = position_data["deprecated"]
msg = "There is a deprecation message but the stability is set to '{}'".format(
stability
)
msg = f"There is a deprecation message but the stability is set to '{stability}'"
raise ValidationError.from_yaml_pos(position, msg)
if AttributeType.get_type(deprecated) != "string" or deprecated == "":
position = position_data["deprecated"]
Expand Down Expand Up @@ -322,7 +318,7 @@ def check_stability(stability_value, position):
val = stability_value_map.get(stability_value)
if val is not None:
return val
msg = "Value '{}' is not allowed as a stability marker".format(stability_value)
msg = f"Value '{stability_value}' is not allowed as a stability marker"
raise ValidationError.from_yaml_pos(position, msg)

def equivalent_to(self, other: "SemanticAttribute"):
Expand Down Expand Up @@ -387,16 +383,12 @@ def check_examples_type(attr_type, examples, zlass):
for element in example:
if not isinstance(element, zlass):
position = examples.lc.data[index]
msg = "Example with wrong type. Expected {} examples but is was {}.".format(
attr_type, type(element)
)
msg = f"Example with wrong type. Expected {attr_type} examples but is was {type(element)}."
raise ValidationError.from_yaml_pos(position, msg)
else: # Single value example or array example with a single example array
if not isinstance(example, zlass):
position = examples.lc.data[index]
msg = "Example with wrong type. Expected {} examples but is was {}.".format(
attr_type, type(example)
)
msg = f"Example with wrong type. Expected {attr_type} examples but is was {type(example)}."
raise ValidationError.from_yaml_pos(position, msg)

@staticmethod
Expand All @@ -411,7 +403,7 @@ def to_bool(key, parent_object):
if AttributeType.bool_type_false.fullmatch(yaml_value):
return False
position = parent_object.lc.data[key]
msg = "Value '{}' for {} field is not allowed".format(yaml_value, key)
msg = f"Value '{yaml_value}' for {key} field is not allowed"
raise ValidationError.from_yaml_pos(position, msg)


Expand Down Expand Up @@ -444,7 +436,7 @@ def parse(attribute_type):
return attribute_type
# Wrong type used - raise the exception and fill the missing data in the parent
raise ValidationError(
0, 0, "Invalid type: {} is not allowed".format(attribute_type)
0, 0, f"Invalid type: {attribute_type} is not allowed"
)
allowed_keys = ["allow_custom_values", "members"]
mandatory_keys = ["members"]
Expand All @@ -470,7 +462,7 @@ def parse(attribute_type):
if not EnumAttributeType.is_valid_enum_value(member["value"]):
raise ValidationError.from_yaml_pos(
member.lc.data["value"][:2],
"Invalid value used in enum: <{}>".format(member["value"]),
f"Invalid value used in enum: <{member['value']}>",
)
validate_id(member["id"], member.lc.data["id"])
members.append(
Expand All @@ -486,7 +478,7 @@ def parse(attribute_type):
if enum_type != AttributeType.get_type(m.value):
raise ValidationError.from_yaml_pos(
myaml.lc.data["value"],
"Enumeration member does not have type {}!".format(enum_type),
f"Enumeration member does not have type {enum_type}!",
)
return EnumAttributeType(custom_values, members, enum_type)

Expand All @@ -508,7 +500,7 @@ def __init__(self, text, url):
self.url = url

def __str__(self):
return "[{}]({})".format(self.text, self.url)
return f"[{self.text}]({self.url})"


class TextWithLinks(str):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,14 @@ def SemanticConvention(group):
line = group.lc.data["id"][0] + 1
doc_url = "https://github.com/open-telemetry/build-tools/blob/main/semantic-conventions/syntax.md#groups"
print(
"Please set the type for group '{}' on line {} - defaulting to type 'span'. See {}".format(
group["id"], line, doc_url
),
f"Please set the type for group '{group['id']}' on line {line} - defaulting to type 'span'. See {doc_url}",
file=sys.stderr,
)

convention_type = parse_semantic_convention_type(type_value)
if convention_type is None:
position = group.lc.data["type"] if "type" in group else group.lc.data["id"]
msg = "Invalid value for semantic convention type: {}".format(group.get("type"))
msg = f"Invalid value for semantic convention type: {group.get('type')}"
raise ValidationError.from_yaml_pos(position, msg)

# First, validate that the correct fields are available in the yaml
Expand Down Expand Up @@ -211,7 +209,7 @@ def __init__(self, group):
self.span_kind = SpanKind.parse(group.get("span_kind"))
if self.span_kind is None:
position = group.lc.data["span_kind"]
msg = "Invalid value for span_kind: {}".format(group.get("span_kind"))
msg = f"Invalid value for span_kind: {group.get('span_kind')}"
raise ValidationError.from_yaml_pos(position, msg)


Expand Down Expand Up @@ -267,17 +265,15 @@ def parse(self, file):
for model in semconv_models:
if model.semconv_id in self.models:
self.errors = True
print("Error parsing {}\n".format(file), file=sys.stderr)
print(f"Error parsing {file}\n", file=sys.stderr)
print(
"Semantic convention '{}' is already defined.".format(
model.semconv_id
),
f"Semantic convention '{model.semconv_id}' is already defined.",
file=sys.stderr,
)
self.models[model.semconv_id] = model
except ValidationError as e:
self.errors = True
print("Error parsing {}\n".format(file), file=sys.stderr)
print(f"Error parsing {file}\n", file=sys.stderr)
print(e, file=sys.stderr)

def has_error(self):
Expand All @@ -291,9 +287,8 @@ def check_unique_fqns(self):
if attr.fqn in group_by_fqn:
self.errors = True
print(
"Attribute {} of Semantic convention '{}' is already defined in {}.".format(
attr.fqn, model.semconv_id, group_by_fqn.get(attr.fqn)
),
f"Attribute {attr.fqn} of Semantic convention '{model.semconv_id}'"
"is already defined in {group_by_fqn.get(attr.fqn)}.",
file=sys.stderr,
)
group_by_fqn[attr.fqn] = model.semconv_id
Expand Down Expand Up @@ -351,9 +346,8 @@ def _populate_extends_single(self, semconv, unprocessed):
if extended is None:
raise ValidationError.from_yaml_pos(
semconv._position,
"Semantic Convention {} extends {} but the latter cannot be found!".format(
semconv.semconv_id, semconv.extends
),
f"Semantic Convention {semconv.semconv_id} extends "
"{semconv.extends} but the latter cannot be found!",
)

# Process hierarchy chain
Expand Down Expand Up @@ -415,9 +409,8 @@ def _populate_anyof_attributes(self):
if ref_attr is None:
raise ValidationError.from_yaml_pos(
any_of._yaml_src_position[index],
"Any_of attribute '{}' of semantic convention {} does not exists!".format(
attr_id, semconv.semconv_id
),
f"Any_of attribute '{attr_id}' of semantic convention "
"{semconv.semconv_id} does not exists!",
)
constraint_attrs.append(ref_attr)
if constraint_attrs:
Expand All @@ -431,17 +424,14 @@ def _populate_events(self):
if event is None:
raise ValidationError.from_yaml_pos(
semconv._position,
"Semantic Convention {} has {} as event but the latter cannot be found!".format(
semconv.semconv_id, event_id
),
f"Semantic Convention {semconv.semconv_id} has "
"{event_id} as event but the latter cannot be found!",
)
if not isinstance(event, EventSemanticConvention):
raise ValidationError.from_yaml_pos(
semconv._position,
"Semantic Convention {} has {} as event but"
" the latter is not a semantic convention for events!".format(
semconv.semconv_id, event_id
),
f"Semantic Convention {semconv.semconv_id} has {event_id} as event but"
" the latter is not a semantic convention for events!",
)
events.append(event)
semconv.events = events
Expand All @@ -457,9 +447,7 @@ def resolve_ref(self, semconv):
if not ref_attr:
raise ValidationError.from_yaml_pos(
semconv._position,
"Semantic Convention {} reference `{}` but it cannot be found!".format(
semconv.semconv_id, attr.ref
),
f"Semantic Convention {semconv.semconv_id} reference `{attr.ref}` but it cannot be found!",
)
attr.attr_type = ref_attr.attr_type
if not attr.brief:
Expand All @@ -484,9 +472,8 @@ def resolve_include(self, semconv):
if include_semconv is None:
raise ValidationError.from_yaml_pos(
semconv._position,
"Semantic Convention {} includes {} but the latter cannot be found!".format(
semconv.semconv_id, constraint.semconv_id
),
f"Semantic Convention {semconv.semconv_id} includes "
"{constraint.semconv_id} but the latter cannot be found!",
)
# We resolve the parent/child relationship of the included semantic convention, if any
self._populate_extends_single(
Expand All @@ -497,9 +484,7 @@ def resolve_include(self, semconv):
if semconv.contains_attribute(attr):
if self.debug:
print(
"[Includes] {} already contains attribute {}".format(
semconv.semconv_id, attr
)
f"[Includes] {semconv.semconv_id} already contains attribute {attr}"
)
continue
# There are changes
Expand Down
10 changes: 4 additions & 6 deletions semantic-conventions/src/opentelemetry/semconv/model/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ def validate_id(semconv_id, position):
if not ID_RE.fullmatch(semconv_id):
raise ValidationError.from_yaml_pos(
position,
"Invalid id {}. Semantic Convention ids MUST match {}".format(
semconv_id, ID_RE.pattern
),
f"Invalid id {semconv_id}. Semantic Convention ids MUST match {ID_RE.pattern}",
)


Expand All @@ -38,7 +36,7 @@ def validate_values(yaml, keys, mandatory=()):
unwanted = [k for k in yaml.keys() if k not in keys]
if unwanted:
position = yaml.lc.data[unwanted[0]]
msg = "Invalid keys: {}".format(unwanted)
msg = f"Invalid keys: {unwanted}"
raise ValidationError.from_yaml_pos(position, msg)
if mandatory:
check_no_missing_keys(yaml, mandatory)
Expand All @@ -48,7 +46,7 @@ def check_no_missing_keys(yaml, mandatory):
missing = list(set(mandatory) - set(yaml))
if missing:
position = (yaml.lc.line, yaml.lc.col)
msg = "Missing keys: {}".format(missing)
msg = f"Missing keys: {missing}"
raise ValidationError.from_yaml_pos(position, msg)


Expand All @@ -68,7 +66,7 @@ def validate_keys(cls, node):
unwanted = [key for key in node.keys() if key not in cls.allowed_keys]
if unwanted:
position = node.lc.data[unwanted[0]]
msg = "Invalid keys: {}".format(unwanted)
msg = f"Invalid keys: {unwanted}"
raise ValidationError.from_yaml_pos(position, msg)

if cls.mandatory_keys:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def to_html_links(doc_string: typing.Optional[typing.Union[str, TextWithLinks]])
if isinstance(elm, str):
str_list.append(elm)
else:
str_list.append('<a href="{}">{}</a>'.format(elm.url, elm.text))
str_list.append(f'<a href="{elm.url}">{elm.text}</a>')
doc_string = "".join(str_list)
doc_string = doc_string.strip()
if doc_string.endswith("."):
Expand Down Expand Up @@ -157,7 +157,7 @@ def to_camelcase(name: str, first_upper=False) -> str:


class CodeRenderer:
pattern = "{{{}}}".format(ID_RE.pattern)
pattern = f"{{{ID_RE.pattern}}}"
matcher = re.compile(pattern)

parameters: typing.Dict[str, str]
Expand Down
Loading