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

Avoid crash with None tasks #1048

Merged
merged 1 commit into from Nov 2, 2020
Merged

Avoid crash with None tasks #1048

merged 1 commit into from Nov 2, 2020

Conversation

ssbarnea
Copy link
Member

As ansible allows tasks to be None, we should also avoid crashing when
encountering them.

Includes regression prevention by assuring we can parse files
with empty tasks.

Fixes: #468

Copy link

@rafaelfolco rafaelfolco left a comment

Choose a reason for hiding this comment

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

empty name with no action would be a good test case, isn't it?

examples/example.yml Show resolved Hide resolved
Copy link
Contributor

@greg-hellings greg-hellings left a comment

Choose a reason for hiding this comment

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

The if foo in (bar or []): is weird syntax to my eyes. Took me a minute to get what it's doing, I've just never seen it used like this in Python before. Once I got my eyes wrapped around it, this looks good.

@ssbarnea
Copy link
Member Author

ssbarnea commented Oct 2, 2020

The if foo in (bar or []): is weird syntax to my eyes. Took me a minute to get what it's doing, I've just never seen it used like this in Python before. Once I got my eyes wrapped around it, this looks good.

Yes is weird, probably if bar and foo in bar would look better? Even so they both serve the same purpose.

I guess you need a better python knowledge to know that "False or []" returns [] and not False (but is evaluated as False if needed).

As ansible allows tasks to be None, we should also avoid crashing when
encountering them.

Includes regression prevention by assuring we can parse files
with empty tasks.

Fixes: #468
@greg-hellings
Copy link
Contributor

The if foo in (bar or []): is weird syntax to my eyes. Took me a minute to get what it's doing, I've just never seen it used like this in Python before. Once I got my eyes wrapped around it, this looks good.

Yes is weird, probably if bar and foo in bar would look better? Even so they both serve the same purpose.

I guess you need a better python knowledge to know that "False or []" returns [] and not False (but is evaluated as False if needed).

Yes, I've seen it used in assignment and short-hand execution but hadn't seen it used in a conditional before. I agree that this form is the more commonly encountered conditional guard from my experience.

Copy link
Contributor

@greg-hellings greg-hellings left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@albinvass albinvass left a comment

Choose a reason for hiding this comment

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

lgtm

@ssbarnea ssbarnea merged commit a3a4e52 into master Nov 2, 2020
@ssbarnea ssbarnea deleted the fix/empty-task branch November 2, 2020 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Empty task "-" crashes ansible-lint
4 participants