Adopt maintainable, idiomatic Python patterns to improve readability and reduce future change risk.
isinstance() over type(...) == ...Use idiomatic checks and keep conversions explicit.
pr_types = []
if 'PR Type' in data:
val = data['PR Type']
pr_types = val if isinstance(val, list) else val.split(',')
Use None and initialize inside the function.
def try_fix_yaml(response_text: str, keys_fix_yaml: list[str] | None = None) -> dict:
keys_fix_yaml = keys_fix_yaml or []
...
Keep public/entry methods short and readable by moving validation into is_valid_* functions.
def publish_code_suggestions(self, code_suggestions: list[dict]):
for suggestion in code_suggestions:
if not self.is_valid_suggestion(suggestion):
continue
...
def is_valid_suggestion(self, suggestion: dict) -> bool:
start = suggestion['relevant_lines_start']
end = suggestion['relevant_lines_end']
if (not start) or start == -1:
return False
return end >= start
Params dataclass) instead of long signatures.These rules directly support the discussed improvements in typing correctness, safe defaults, readability, and maintainability—core concerns for code style.