Skip to content

Commit

Permalink
[pylint] client constructor should take a credential param (not crede…
Browse files Browse the repository at this point in the history
…ntials) (#6887)

* client constructor takes credential (singular) param

* update readme for run at repo root

* update readme table
  • Loading branch information
kristapratico authored Aug 22, 2019
1 parent f522fca commit 0b0aded
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions scripts/pylint_custom_plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Check that you are running pylint version >=2.31 and astroid version >=2.25.

1. Run pylint at the root of the repo and it will automatically find the pylintrc:
```bash
C:\azure-sdk-for-python>pylint sdk/storage/azure-storage-blob
C:\azure-sdk-for-python>pylint sdk/storage/azure-storage-blob/azure
```
2. Add the --rcfile command line argument with a relative path to the pylintrc from your current directory:
```bash
Expand Down Expand Up @@ -44,7 +44,7 @@ In the case of a false positive, use the disable command to remove the pylint er
| Pylint checker name | How to fix this | How to disable this rule | Link to python guideline |
|----------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------|
| client-method-should-not-use-static-method | Use module level functions instead. | # pylint:disable=connection-string-should-not-be-constructor-param | [link](https://azure.github.io/azure-sdk/python_design.html#constructors-and-factory-methods) |
| missing-client-constructor-parameter-credentials | Add a credential parameter to the client constructor. | # pylint:disable=missing-client-constructor-parameter-credentials | [link](https://azure.github.io/azure-sdk/python_design.html#constructors-and-factory-methods) |
| missing-client-constructor-parameter-credential | Add a credential parameter to the client constructor. Do not use plural form "credentials". | # pylint:disable=missing-client-constructor-parameter-credential | [link](https://azure.github.io/azure-sdk/python_design.html#constructors-and-factory-methods) |
| missing-client-constructor-parameter-kwargs | Add a **kwargs parameter to the client constructor. | # pylint:disable=missing-client-constructor-parameter-kwargs | [link](https://azure.github.io/azure-sdk/python_design.html#constructors-and-factory-methods) |
| client-method-has-more-than-5-positional-arguments | Use keyword arguments to reduce number of positional arguments. | # pylint:disable=client-method-has-more-than-5-positional-arguments | [link](https://azure.github.io/azure-sdk/python_introduction.html#method-signatures) |
| client-method-missing-type-annotations | Check that param/return type comments are present or that param/return type annotations are present. Check that you did not mix type comments with type annotations. | # pylint:disable=client-method-missing-type-annotations | [link](https://azure.github.io/azure-sdk/python_introduction.html#types-or-not) |
Expand Down
16 changes: 8 additions & 8 deletions scripts/pylint_custom_plugin/pylint_guidelines_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class ClientConstructorTakesCorrectParameters(BaseChecker):
priority = -1
msgs = {
"C4717": (
"Client constructor is missing a credentials parameter. See details:"
"Client constructor is missing a credential parameter. See details:"
" https://azure.github.io/azure-sdk/python_design.html#constructors-and-factory-methods",
"missing-client-constructor-parameter-credentials",
"All client types should accept a credentials parameter.",
"missing-client-constructor-parameter-credential",
"All client types should accept a credential parameter.",
),
"C4718": (
"Client constructor is missing a **kwargs parameter. See details:"
Expand All @@ -35,12 +35,12 @@ class ClientConstructorTakesCorrectParameters(BaseChecker):
}
options = (
(
"ignore-missing-client-constructor-parameter-credentials",
"ignore-missing-client-constructor-parameter-credential",
{
"default": False,
"type": "yn",
"metavar": "<y_or_n>",
"help": "Allow client constructors without a credentials parameter",
"help": "Allow client constructors without a credential parameter",
},
),
(
Expand Down Expand Up @@ -73,7 +73,7 @@ def visit_classdef(self, node):

def visit_functiondef(self, node):
"""Visits the constructor within a client class and checks that it has
credentials and kwargs parameters.
credential and kwargs parameters.
:param node: function node
:type node: ast.FunctionDef
Expand All @@ -85,9 +85,9 @@ def visit_functiondef(self, node):
(child for child in node.get_children() if child.is_argument)
)
arg_names = [argument.name for argument in arguments_node.args]
if "credential" not in arg_names and "credentials" not in arg_names:
if "credential" not in arg_names:
self.add_message(
msg_id="missing-client-constructor-parameter-credentials", node=node, confidence=None
msg_id="missing-client-constructor-parameter-credential", node=node, confidence=None
)
if not arguments_node.kwarg:
self.add_message(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ class TestClientConstructorTakesCorrectParameters(pylint.testutils.CheckerTestCa
def test_finds_correct_params(self):
class_node, function_node = astroid.extract_node("""
class SomeClient(): #@
def __init__(self, thing_url, credentials, **kwargs): #@
def __init__(self, thing_url, credential, **kwargs): #@
pass
""")

Expand Down Expand Up @@ -666,7 +666,7 @@ def __init__(self): #@
def test_finds_constructor_without_kwargs(self):
class_node, function_node = astroid.extract_node("""
class SomeClient(): #@
def __init__(self, thing_url, credentials=None): #@
def __init__(self, thing_url, credential=None): #@
pass
""")

Expand All @@ -687,7 +687,7 @@ def __init__(self, thing_url, **kwargs): #@

with self.assertAddsMessages(
pylint.testutils.Message(
msg_id="missing-client-constructor-parameter-credentials", node=function_node
msg_id="missing-client-constructor-parameter-credential", node=function_node
)
):
self.checker.visit_classdef(class_node)
Expand All @@ -702,7 +702,7 @@ def __init__(self): #@

with self.assertAddsMessages(
pylint.testutils.Message(
msg_id="missing-client-constructor-parameter-credentials", node=function_node
msg_id="missing-client-constructor-parameter-credential", node=function_node
),
pylint.testutils.Message(
msg_id="missing-client-constructor-parameter-kwargs", node=function_node
Expand Down

0 comments on commit 0b0aded

Please sign in to comment.