Skip to content

Commit

Permalink
Add pylint disable for "line-too-long" and "too-many-locals" (#2830)
Browse files Browse the repository at this point in the history
* fix for pylint

* changelog

* lint
  • Loading branch information
msyyc authored Sep 10, 2024
1 parent 9d0e4dd commit db304e9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .chronus/changes/HEAD-2024-8-10-14-24-45.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@azure-tools/typespec-python"
---

Add pylint disable for "line-too-long" and "too-many-locals"
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,18 @@ def declare_property(prop: Property) -> str:
args.append(f"xml={prop.xml_metadata}")

field = "rest_discriminator" if prop.is_discriminator else "rest_field"
type_ignore = prop.is_discriminator and isinstance(prop.type, (ConstantType, EnumValue)) and prop.type.value
return (
f"{prop.client_name}: {prop.type_annotation()} ="
f' {field}({", ".join(args)}){" # type: ignore" if type_ignore else ""}'
type_ignore = (
" # type: ignore"
if prop.is_discriminator and isinstance(prop.type, (ConstantType, EnumValue)) and prop.type.value
else ""
)
generated_code = f'{prop.client_name}: {prop.type_annotation()} = {field}({", ".join(args)})'
pylint_disable = (
" # pylint: disable=line-too-long"
if len(generated_code) <= 120 < (len(generated_code) + len(type_ignore))
else ""
)
return f"{generated_code}{type_ignore}{pylint_disable}"

def initialize_properties(self, model: ModelType) -> List[str]:
init_args = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
{% set need_init = (not model.internal) and (serializer.init_line(model) or model.discriminator)%}
{% if need_init %}
@overload
def __init__(
def __init__({{ model.init_pylint_disable }}
self,
{% for param_signature in serializer.init_line(model) %}
{{ param_signature }}
Expand Down

0 comments on commit db304e9

Please sign in to comment.