Skip to content

Commit

Permalink
Merge branch 'master' into bug_pylint_3885
Browse files Browse the repository at this point in the history
  • Loading branch information
hippo91 committed Oct 24, 2020
2 parents 033f635 + acf39ac commit ee15027
Show file tree
Hide file tree
Showing 21 changed files with 828 additions and 80 deletions.
6 changes: 6 additions & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ contributors:

* Frost Ming (frostming): contributor

* Luigi Bertaco Cristofolini (luigibertaco): contributor

* Eli Fine (eli88fine): Fixed false positive duplicate code warning for lines with symbols only

* Ganden Schaffner: contributor
Expand All @@ -412,8 +414,12 @@ contributors:

* David Cain: contributor

* Pedro Algarvio (s0undt3ch): contributor

* Luigi Bertaco Cristofolini (luigibertaco): contributor

* Or Bahari

* Joshua Cannon: contributor

* Giuseppe Valente: contributor
17 changes: 15 additions & 2 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@ Release date: TBA

Closes #3885

* Fix bug that lead to duplicate messages when using ``--jobs 2`` or more.

Close #3584

* Adds option ``check-protected-access-in-special-methods`` in the ClassChecker to activate/deactivate
``protected-access`` message emission for single underscore prefixed attribute in special methods.

Close #3120

* Fix vulnerable regular expressions in ``pyreverse``

Close #3811

Release date: TBA

* ``inconsistent-return-statements`` message is now emitted if one of ``try/except`` statement
is not returning explicitly while the other do.

Expand All @@ -33,6 +40,10 @@ Release date: TBA

* Fix a crash when a specified config file does not exist

* Add support to ``ignored-argument-names`` in DocstringParameterChecker and adds `useless-param-doc` and `useless-type-doc` messages.

Close #3800

* Fix ``duplicate-code`` false positive when lines only contain whitespace and non-alphanumeric characters (e.g. parentheses, bracket, comman, etc.)

* Improve lint message for `singleton-comparison` with bools
Expand All @@ -43,6 +54,8 @@ Release date: TBA

* Fix AttributeError in checkers/refactoring.py

* Improve sphinx directives spelling filter

* Fix a bug with postponed evaluation when using aliases for annotations.

Close #3798
Expand Down
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3.9.0-alpine3.12

COPY ./ /tmp/build
WORKDIR /tmp/build
RUN python setup.py install && rm -rf /tmp/build

ENTRYPOINT ["pylint"]
44 changes: 18 additions & 26 deletions doc/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ entirety:

1 #!/usr/bin/env python3
2
3 import string
3 import string;
4
5 shift = 3
6 choice = input("would you like to encode or decode?")
Expand All @@ -118,7 +118,7 @@ entirety:
13 encoded = encoded + ' '
14 else:
15 x = letters.index(letter) + shift
16 encoded=encoded + letters[x]
16 encoded = encoded + letters[x]
17 if choice == "decode":
18 for letter in word:
19 if letter == ' ':
Expand All @@ -138,39 +138,34 @@ If we run this:

robertk01 Desktop$ pylint simplecaesar.py
************* Module simplecaesar
simplecaesar.py:16:19: C0326: Exactly one space required around assignment
encoded=encoded + letters[x]
^ (bad-whitespace)
simplecaesar.py:1:0: C0111: Missing module docstring (missing-docstring)
simplecaesar.py:3:0: W0301: Unnecessary semicolon (unnecessary-semicolon)
simplecaesar.py:1:0: C0114: Missing module docstring (missing-module-docstring)
simplecaesar.py:5:0: C0103: Constant name "shift" doesn't conform to UPPER_CASE naming style (invalid-name)
simplecaesar.py:6:0: C0103: Constant name "choice" doesn't conform to UPPER_CASE naming style (invalid-name)
simplecaesar.py:7:0: C0103: Constant name "word" doesn't conform to UPPER_CASE naming style (invalid-name)
simplecaesar.py:8:0: C0103: Constant name "letters" doesn't conform to UPPER_CASE naming style (invalid-name)
simplecaesar.py:9:0: C0103: Constant name "encoded" doesn't conform to UPPER_CASE naming style (invalid-name)
simplecaesar.py:13:12: C0103: Constant name "encoded" doesn't conform to UPPER_CASE naming style (invalid-name)

-----------------------------------
Your code has been rated at 6.32/10
Your code has been rated at 7.37/10


Previous experience taught me that the default output for the messages
needed a bit more info. We can see the second line is: ::

"simplecaesar.py:1:0: C0111: Missing module docstring (missing-docstring)"
"simplecaesar.py:1:0: C0114: Missing module docstring (missing-module-docstring)"

This basically means that line 1 violates a convention ``C0111``. It's telling me I really should have a docstring. I agree, but what if I didn't fully understand what rule I violated. Knowing only that I violated a convention
isn't much help if I'm a newbie. Another piece of information there is the
message symbol between parens, ``missing-docstring`` here.
message symbol between parens, ``missing-module-docstring`` here.

If I want to read up a bit more about that, I can go back to the
command line and try this:

.. sourcecode:: console

robertk01 Desktop$ pylint --help-msg=missing-docstring
:missing-docstring (C0111): *Missing %s docstring*
Used when a module, function, class or method has no docstring. Some special
methods like __init__ don't necessarily require a docstring. This message
belongs to the basic checker.
robertk01 Desktop$ pylint --help-msg=missing-module-docstring
:missing-module-docstring (C0114): *Missing module docstring*
Used when a module has no docstring.Empty modules do not require a docstring.
This message belongs to the basic checker.


Yeah, ok. That one was a bit of a no-brainer, but I have run into error messages
Expand All @@ -192,9 +187,9 @@ do with the remaining warnings.

If we add a docstring to describe what the code is meant to do that will help.
There are 5 ``invalid-name`` messages that we will get to later. Lastly, I
violated the convention of using spaces around an operator such as ``=`` so I'll
fix that too. To sum up, I'll add a docstring to line 2, and put spaces around
the ``=`` sign on line 16.
put an unnecessary semicolon at the end of the import line so I'll
fix that too. To sum up, I'll add a docstring to line 2, and remove the ``;``
from line 3.

Here is the updated code:

Expand Down Expand Up @@ -235,14 +230,11 @@ Here is what happens when we run it:
robertk01 Desktop$ pylint simplecaesar.py
************* Module simplecaesar
simplecaesar.py:7:0: C0103: Constant name "shift" doesn't conform to UPPER_CASE naming style (invalid-name)
simplecaesar.py:8:0: C0103: Constant name "choice" doesn't conform to UPPER_CASE naming style (invalid-name)
simplecaesar.py:9:0: C0103: Constant name "word" doesn't conform to UPPER_CASE naming style (invalid-name)
simplecaesar.py:10:0: C0103: Constant name "letters" doesn't conform to UPPER_CASE naming style (invalid-name)
simplecaesar.py:11:0: C0103: Constant name "encoded" doesn't conform to UPPER_CASE naming style (invalid-name)
simplecaesar.py:15:12: C0103: Constant name "encoded" doesn't conform to UPPER_CASE naming style (invalid-name)

------------------------------------------------------------------
Your code has been rated at 7.37/10 (previous run: 6.32/10, +1.05)

Your code has been rated at 8.42/10 (previous run: 7.37/10, +1.05)

Nice! Pylint told us how much our code rating has improved since our last run, and we're down to just the ``invalid-name`` messages.

Expand All @@ -269,7 +261,7 @@ will now be quite quiet:
robertk01 Desktop$ pylint --const-rgx='[a-z_][a-z0-9_]{2,30}$' simplecaesar.py

-------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 7.37/10, +2.63)
Your code has been rated at 10.00/10 (previous run: 8.42/10, +1.58)


Regular expressions can be quite a beast so take my word on this particular
Expand Down
10 changes: 10 additions & 0 deletions doc/whatsnew/2.6.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ Summary -- Release highlights
New checkers
============

* Add support to ``ignored-argument-names`` in DocstringParameterChecker and
adds `useless-param-doc` and `useless-type-doc` messages.

* Add `empty-comment` check for empty comments.

* Add `super-with-arguments` check for flagging instances of Python 2 style super calls.

* Add `raise-missing-from` check for exceptions that should have a cause.
Expand All @@ -24,6 +29,11 @@ New checkers
Other Changes
=============

* Fix bug that lead to duplicate messages when using ``--jobs 2`` or more.

* Adds option ``check-protected-access-in-special-methods`` in the ClassChecker to activate/deactivate
``protected-access`` message emission for single underscore prefixed attribute in special methods.

* ``inconsistent-return-statements`` message is now emitted if one of ``try/except`` statement
is not returning explicitly while the other do.

Expand Down
23 changes: 0 additions & 23 deletions doc/whatsnew/2.7.rst

This file was deleted.

1 change: 0 additions & 1 deletion doc/whatsnew/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ High level descriptions of the most important changes between major Pylint versi
.. toctree::
:maxdepth: 1

2.7.rst
2.6.rst
2.5.rst
2.4.rst
Expand Down
20 changes: 16 additions & 4 deletions pylint/checkers/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,15 @@ class ClassChecker(BaseChecker):
),
},
),
(
"check-protected-access-in-special-methods",
{
"default": False,
"type": "yn",
"metavar": "<y or n>",
"help": "Warn about protected attribute access inside special methods",
},
),
)

def __init__(self, linter=None):
Expand Down Expand Up @@ -1418,10 +1427,13 @@ def _check_protected_attribute_access(self, node):
if _is_attribute_property(name, klass):
return

# A licit use of protected member is inside a special method
if not attrname.startswith(
"__"
) and self._is_called_inside_special_method(node):
if (
not self.config.check_protected_access_in_special_methods
and
# A licit use of protected member is inside a special method
not attrname.startswith("__")
and self._is_called_inside_special_method(node)
):
return

self.add_message("protected-access", node=node, args=attrname)
Expand Down
12 changes: 9 additions & 3 deletions pylint/checkers/refactoring/refactoring_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1332,9 +1332,15 @@ def _is_node_return_ended(self, node: astroid.node_classes.NodeNG) -> bool:
if isinstance(node, astroid.If):
return self._is_if_node_return_ended(node)
if isinstance(node, astroid.TryExcept):
return all(
self._is_node_return_ended(_child) for _child in node.get_children()
)
handlers = {
_child
for _child in node.get_children()
if isinstance(_child, astroid.ExceptHandler)
}
all_but_handler = set(node.get_children()) - handlers
return any(
self._is_node_return_ended(_child) for _child in all_but_handler
) and all(self._is_node_return_ended(_child) for _child in handlers)
# recurses on the children of the node
return any(self._is_node_return_ended(_child) for _child in node.get_children())

Expand Down
4 changes: 2 additions & 2 deletions pylint/checkers/spelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ class SphinxDirectives(Filter):
r"""Filter skipping over Sphinx Directives.
This filter skips any words matching the following regular expression:
^:([a-z]+):`([^`]+)(`)?
^(:([a-z]+)){1,2}:`([^`]+)(`)?
That is, for example, :class:`BaseQuery`
"""
# The final ` in the pattern is optional because enchant strips it out
_pattern = re.compile(r"^:([a-z]+):`([^`]+)(`)?")
_pattern = re.compile(r"^(:([a-z]+)){1,2}:`([^`]+)(`)?")

def _skip(self, word):
return bool(self._pattern.match(word))
Expand Down
Loading

0 comments on commit ee15027

Please sign in to comment.