Skip to content

Bugfix: Verify the element in item_context.args is of type ast.Name - #166

Merged
cooperlees merged 12 commits into
PyCQA:masterfrom
cricalix:master
Apr 1, 2021
Merged

cooperlees merged 12 commits into
PyCQA:masterfrom
cricalix:master

Conversation

@cricalix

@cricalix cricalix commented Apr 1, 2021 •

Copy link
Copy Markdown
Contributor

The sample case that broke the assumptions in the code was doing a module.Error type assertRaises. In this case, item_context.args[0] is now a Call object (without an id attr), not a Name object. So, qualify the conditions even more, and add a test case for the sample provided by @DStape.

Should address #164

cricalix and others added 12 commits March 30, 2021 10:50
```with assertRaises(Exception):``` is basically a "catch 'em all" assert that casts far too broad of a net when it comes to detecting failures in code being tested. Assertions should be testing specific failure cases, not "did Python throw /any/ type of error?", and so the context manager form, or the assertRaisesRegex form are far better to use.
Attempts to ensure we're only looking at Name type objects in the item_context.args, since apparently this code is still matching other objects that don't have an id attr.
@cricalix cricalix changed the title Bugfix: Fix #164 again by adding another conditional Bugfix: Verify the element in item_context.args is of type ast.Name Apr 1, 2021

@cooperlees cooperlees left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ast is fun. Ok, some more edge cases covered. Hopefully this gets majority.

@cooperlees
cooperlees merged commit 3cab68c into PyCQA:master Apr 1, 2021
@DStape

DStape commented Apr 2, 2021

Copy link
Copy Markdown

Thank you @cricalix and @cooperlees , this diff (v21.4.3) solves the error on my end.

@cooperlees

Copy link
Copy Markdown
Collaborator

Thanks, sorry for causing it. We needed to do better testing here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants