Skip to content
Merged
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 src/pre_commit_terraform/terraform_docs_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def invoke_cli_app(parsed_cli_args: Namespace) -> ReturnCodeType:
category=UserWarning,
)

dirs = []
dirs: list[str] = []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too pythonish for me 🤣

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<variable_name>[: <variable_type>] = <variable_value>

Actually, I think that = <variable_value> is optional too, but I can't remember when I saw such usage last time. It could be forbidden by most basic linters, tbh.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not forbidden. You can declare a type of a variable before you actually initialize it. For most simple types, the type checkers like MyPy would infer the type of the data intended to be stored there. But when it's an empty container, like a list, it's ambiguous. dirs = [] made MyPy think the type was list[typing.Any] while a more precise type should be list[str].

When declaring typing, the guidance is to use a narrow type when returning things from functions but wide types for the incoming function arguments. It allows passing more shapes of data into functions while being accurate regarding what they return. Individual variables should also be as accurate as possible.

for filename in cast_to(list[str], parsed_cli_args.filenames):
if (os.path.realpath(filename) not in dirs and
(filename.endswith(".tf") or filename.endswith(".tfvars"))):
Expand Down
Loading