Skip to content

Conversation

@cfournie
Copy link
Contributor

@cfournie cfournie commented Aug 18, 2017

Problem

We're missing a few binary operators and there are a few situations when node.body.operand doesn't have a name during the check for whether we can use an operator function as opposed to a lambda function, e.g.:

Linting lambda key: not type_allowed(key._type) throws

if operator and not isinstance(node.body.operand, astroid.BinOp) and argname is node.body.operand.name:
17 AttributeError: 'Call' object has no attribute 'name'

Linting lambda key: not self.OUTPUT[key]["nullable"] throws

if operator and not isinstance(node.body.operand, astroid.BinOp) and argname is node.body.operand.name:
17 AttributeError: 'Subscript' object has no attribute 'name'

Linting lambda job: not job.is_loader throws

if operator and not isinstance(node.body.operand, astroid.BinOp) and argname is node.body.operand.name:
17 AttributeError: 'Attribute' object has no attribute 'name'

Solution

This PR:

  • Adds some of the missing binary operators and reorders them to better match this list,
  • Makes the operator check optional by calling get on the dictionary of them to prevent future exceptions from being thrown (resulting in potential false negatives for operators that aren't included, bugs can be reported to add them)
  • Checks to ensure that the operand has a name before trying to use its name to prevent exceptions

pylintrc Outdated

# Maximum number of public methods for a class (see R0904).
max-public-methods=20
max-public-methods=22
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TestGoogleStyleGuideChecker now has 21 public methods; this class should be refactored in a future PR and this max lowered (#84).

Copy link
Contributor

Choose a reason for hiding this comment

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

Why up the limit here instead of adding a # pylint: disable=... directive in the relevant file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally I'd set the max public methods for that one class to 21 temporarily. Reconsidering, maybe a global change is a bad idea. Opting instead for a local one.

@cfournie cfournie changed the title [WIP] Fix lambda_func and operators Fix lambda_func and operators Aug 18, 2017
Copy link

@sabidib sabidib left a comment

Choose a reason for hiding this comment

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

LGTM

@cfournie cfournie merged commit d83287a into master Aug 23, 2017
@cfournie cfournie deleted the operators branch August 23, 2017 20:05
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.

4 participants