Skip to content

Commit

Permalink
[pre-commit] Add codespell, and fix some existing typos (#9912)
Browse files Browse the repository at this point in the history
* Add the spellchecker codespell to the pre-commit configuration
* Make the dict name generic now that it's used by multiple tools
* Fix existing typos
* Sort the custom dict
  • Loading branch information
Pierre-Sassoulas committed Sep 19, 2024
1 parent 3b4a7f9 commit 0950916
Show file tree
Hide file tree
Showing 39 changed files with 105 additions and 63 deletions.
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ repos:
hooks:
- id: trailing-whitespace
exclude: tests(/\w*)*/functional/t/trailing_whitespaces.py|tests/pyreverse/data/.*.html|doc/data/messages/t/trailing-whitespace/bad.py
# - id: file-contents-sorter # commented out because it does not preserve comments order
# args: ["--ignore-case", "--unique"]
# files: "custom_dict.txt"
- id: end-of-file-fixer
exclude: |
(?x)^(
Expand Down Expand Up @@ -173,3 +176,10 @@ repos:
- id: bandit
args: ["-r", "-lll"]
exclude: *fixtures
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
args: ["--toml=pyproject.toml"]
additional_dependencies:
- tomli
21 changes: 12 additions & 9 deletions .pyenchant_pylint_custom_dict.txt → custom_dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ argumentparser
argumentsparser
argv
ascii
asend
assignattr
assignname
ast
AST
ast
astroid
async
asynccontextmanager
Expand Down Expand Up @@ -67,8 +68,8 @@ contextlib
contextmanager
contravariance
contravariant
cpython
CPython
cpython
csv
CVE
cwd
Expand Down Expand Up @@ -126,8 +127,8 @@ formfeed
fromlineno
fullname
func
functiøn
functiondef
functiøn
functools
genexpr
getattr
Expand Down Expand Up @@ -160,10 +161,11 @@ isfile
isinstance
isort
iter
itered
iterable
iterables
itered
iteritems
iTerm
jn
jpg
json
Expand Down Expand Up @@ -206,10 +208,10 @@ monkeypatch
mro
# Used so much that we need the abbreviation
msg
msg-template
msgid
msgids
msgs
msg-template
mult
multiline
multiset
Expand Down Expand Up @@ -250,8 +252,8 @@ parens
passthru
pathlib
patternerror
positionals
png
positionals
pragma
pragma's
pragmas
Expand All @@ -264,9 +266,9 @@ pyenchant
pyfile
pyi
pylint
pylint's
pylintdict
pylintrc
pylint's
pyproject
pypy
pyreverse
Expand All @@ -275,6 +277,7 @@ qname
rawcheckers
rc
rcfile
re-usable
readlines
recognise
recurse
Expand Down Expand Up @@ -345,9 +348,9 @@ tomlkit
toplevel
towncrier
tp
truthey
truthness
truthy
truthey
tryexcept
txt
typecheck
Expand All @@ -362,8 +365,8 @@ unary
unflattens
unhandled
unicode
Uninferable
uninferable
Uninferable
unittest
unraisablehook
untriggered
Expand Down
2 changes: 1 addition & 1 deletion doc/development_guide/contributor_guide/profiling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ and thus is displayed as being 0.

Often you are more interested in the cumulative time (per call). This refers to the time spent within the function
and any of the functions it called or the functions they called (etc.). In our example, the ``visit_importfrom``
method and all of its child-functions took a little over 8 seconds to exectute, with an execution time of
method and all of its child-functions took a little over 8 seconds to execute, with an execution time of
0.013 ms per call.

You can also search the ``profiler_stats`` for an individual function you want to check. For example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Unittest tests

Most other tests reside in the '/pylint/test' directory. These unittests can be used to test
almost all functionality within Pylint. A good step before writing any new unittests is to look
at some tests that test a similar funcitionality. This can often help write new tests.
at some tests that test a similar functionality. This can often help write new tests.

If your new test requires any additional files you can put those in the
``/pylint/test/regrtest_data`` directory. This is the directory we use to store any data needed for
Expand Down
10 changes: 5 additions & 5 deletions doc/user_guide/checkers/features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -918,16 +918,16 @@ Refactoring checker Messages
Emitted when a single "return" or "return None" statement is found at the end
of function or method definition. This statement can safely be removed
because Python will implicitly return None
:use-implicit-booleaness-not-comparison-to-string (C1804): *"%s" can be simplified to "%s", if it is striclty a string, as an empty string is falsey*
Empty string are considered false in a boolean context. Following this check
blindly in weakly typed code base can create hard to debug issues. If the
value can be something else that is falsey but not a string (for example
``None``, an empty sequence, or ``0``) the code will not be equivalent.
:use-implicit-booleaness-not-comparison (C1803): *"%s" can be simplified to "%s", if it is strictly a sequence, as an empty %s is falsey*
Empty sequences are considered false in a boolean context. Following this
check blindly in weakly typed code base can create hard to debug issues. If
the value can be something else that is falsey but not a sequence (for
example ``None``, an empty string, or ``0``) the code will not be equivalent.
:use-implicit-booleaness-not-comparison-to-string (C1804): *"%s" can be simplified to "%s", if it is strictly a string, as an empty string is falsey*
Empty string are considered false in a boolean context. Following this check
blindly in weakly typed code base can create hard to debug issues. If the
value can be something else that is falsey but not a string (for example
``None``, an empty sequence, or ``0``) the code will not be equivalent.
:use-implicit-booleaness-not-comparison-to-zero (C1805): *"%s" can be simplified to "%s", if it is strictly an int, as 0 is falsey*
0 is considered false in a boolean context. Following this check blindly in
weakly typed code base can create hard to debug issues. If the value can be
Expand Down
2 changes: 1 addition & 1 deletion doc/whatsnew/0/0.x.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ Release date: 2004-10-19
* avoid importing analyzed modules !

* new Refactor and Convention message categories. Some Warnings have been
remaped into those new categories
remapped into those new categories

* added "similar", a tool to find copied and pasted lines of code,
both using a specific command line tool and integrated as a
Expand Down
2 changes: 1 addition & 1 deletion doc/whatsnew/1/1.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ Release date: 2015-11-29
* astroid.utils.LocalsVisitor was moved to pylint.pyreverse.LocalsVisitor.

* pylint.checkers.utils.excepts_import_error was removed.
Use pylint.chekcers.utils.error_of_type instead.
Use pylint.checkers.utils.error_of_type instead.

* Don't emit undefined-all-variables for nodes which can't be
inferred (YES nodes).
Expand Down
2 changes: 1 addition & 1 deletion doc/whatsnew/2/2.0/summary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ Other Changes
``pylint`` should be a bit faster as well.

We added a new flag, ``max_inferable_values`` on ``astroid.MANAGER`` for
limitting the maximum amount of values that ``astroid`` can infer when inferring
limiting the maximum amount of values that ``astroid`` can infer when inferring
values. This change should improve the performance when dealing with large frameworks
such as ``django``.
You can also control this behaviour with ``pylint --limit-inference-results``
Expand Down
2 changes: 1 addition & 1 deletion doc/whatsnew/2/2.13/summary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ New checkers
creates memory leaks by never letting the instance get garbage collected.

Closes #5670
Clsoes #6180
Closes #6180

Removed checkers
================
Expand Down
2 changes: 1 addition & 1 deletion doc/whatsnew/2/2.4/full.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Release date: 2019-09-24
Closes #2925

* ``useless-suppression`` check now ignores ``cyclic-import`` suppressions,
which could lead to false postiives due to incomplete context at the time
which could lead to false positives due to incomplete context at the time
of the check.

Closes #3064
Expand Down
2 changes: 1 addition & 1 deletion doc/whatsnew/2/2.6/full.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Release date: 2020-08-20

* Add ``raise-missing-from`` check for exceptions that should have a cause.

* Support both isort 4 and isort 5. If you have pinned isort 4 in your projet requirements, nothing changes. If you use isort 5, though, note that the ``known-standard-library`` option is not interpreted the same in isort 4 and isort 5 (see the migration guide in isort documentation for further details). For compatibility's sake for most pylint users, the ``known-standard-library`` option in pylint now maps to ``extra-standard-library`` in isort 5. If you really want what ``known-standard-library`` now means in isort 5, you must disable the ``wrong-import-order`` check in pylint and run isort manually with a proper isort configuration file.
* Support both isort 4 and isort 5. If you have pinned isort 4 in your project requirements, nothing changes. If you use isort 5, though, note that the ``known-standard-library`` option is not interpreted the same in isort 4 and isort 5 (see the migration guide in isort documentation for further details). For compatibility's sake for most pylint users, the ``known-standard-library`` option in pylint now maps to ``extra-standard-library`` in isort 5. If you really want what ``known-standard-library`` now means in isort 5, you must disable the ``wrong-import-order`` check in pylint and run isort manually with a proper isort configuration file.

Closes #3722

Expand Down
2 changes: 1 addition & 1 deletion doc/whatsnew/2/2.6/summary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ Other Changes

* Fix superfluous-parens false-positive for the walrus operator

* Add support for both isort 4 and isort 5. If you have pinned isort 4 in your projet requirements, nothing changes. If you use isort 5, though, note that the ``known-standard-library`` option is not interpreted the same in isort 4 and isort 5 (see `the migration guide in isort documentation` (no longer available) for further details). For compatibility's sake for most pylint users, the ``known-standard-library`` option in pylint now maps to ``extra-standard-library`` in isort 5. If you really want what ``known-standard-library`` now means in isort 5, you must disable the ``wrong-import-order`` check in pylint and run isort manually with a proper isort configuration file.
* Add support for both isort 4 and isort 5. If you have pinned isort 4 in your project requirements, nothing changes. If you use isort 5, though, note that the ``known-standard-library`` option is not interpreted the same in isort 4 and isort 5 (see `the migration guide in isort documentation` (no longer available) for further details). For compatibility's sake for most pylint users, the ``known-standard-library`` option in pylint now maps to ``extra-standard-library`` in isort 5. If you really want what ``known-standard-library`` now means in isort 5, you must disable the ``wrong-import-order`` check in pylint and run isort manually with a proper isort configuration file.
2 changes: 1 addition & 1 deletion doc/whatsnew/3/3.1/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Other Bug Fixes
The message will report imports as follows:
For "import X", it will report "(standard/third party/first party/local) import X"
For "import X.Y" and "from X import Y", it will report "(standard/third party/first party/local) import X.Y"
The import category is specified to provide explanation as to why pylint has issued the message and guidence to the developer on how to fix the problem.
The import category is specified to provide explanation as to why pylint has issued the message and guidance to the developer on how to fix the problem.

Closes #8808 (`#8808 <https://github.com/pylint-dev/pylint/issues/8808>`_)

Expand Down
2 changes: 1 addition & 1 deletion pylint/checkers/base/function_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _check_contextmanager_generator_missing_cleanup(
:param node: FunctionDef node to check
:type node: nodes.FunctionDef
"""
# if function does not use a Yield statement, it cant be a generator
# if function does not use a Yield statement, it can't be a generator
with_nodes = list(node.nodes_of_class(nodes.With))
if not with_nodes:
return
Expand Down
2 changes: 1 addition & 1 deletion pylint/checkers/refactoring/implicit_booleaness_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ImplicitBooleanessChecker(checkers.BaseChecker):
"equivalent.",
),
"C1804": (
'"%s" can be simplified to "%s", if it is striclty a string, as an empty string is falsey',
'"%s" can be simplified to "%s", if it is strictly a string, as an empty string is falsey',
"use-implicit-booleaness-not-comparison-to-string",
"Empty string are considered false in a boolean context. Following this"
" check blindly in weakly typed code base can create hard to debug issues."
Expand Down
2 changes: 1 addition & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ spelling-ignore-words=
spelling-ignore-comment-directives=fmt: on,fmt: off,noqa:,noqa,nosec,isort:skip,mypy:,pragma:,# noinspection

# A path to a file that contains private dictionary; one word per line.
spelling-private-dict-file=.pyenchant_pylint_custom_dict.txt
spelling-private-dict-file=custom_dict.txt

# Tells whether to store unknown words to indicated private dictionary in
# --spelling-private-dict-file option instead of raising a message.
Expand Down
29 changes: 29 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,32 @@ ignore = [

[tool.ruff.lint.pydocstyle]
convention = "pep257"

[tool.codespell]
ignore-words = ["custom_dict.txt"]

# Disabled the spelling files for obvious reason, but also,
# the test file with typing extension imported as 'te' and:
# tests/functional/i/implicit/implicit_str_concat_latin1.py:
# - bad encoding
# pylint/pyreverse/diagrams.py and tests/pyreverse/test_diagrams.py:
# - An API from pyreverse use 'classe', and would need to be deprecated
# pylint/checkers/imports.py:
# - 'THIRDPARTY' is a value from isort that would need to be handled even
# if isort fix the typo in newer versions
# tests/functional/m/member/member_checks.py:
# - typos are voluntary to create credible 'no-member'

skip = """
tests/checkers/unittest_spelling.py,\
CODE_OF_CONDUCT.md,\
CONTRIBUTORS.txt,\
pylint/checkers/imports.py,\
pylint/pyreverse/diagrams.py,\
tests/pyreverse/test_diagrams.py,\
tests/functional/i/implicit/implicit_str_concat_latin1.py,\
tests/functional/m/member/member_checks.py,\
tests/functional/t/type/typevar_naming_style_rgx.py,\
tests/functional/t/type/typevar_naming_style_default.py,\
tests/functional/m/member/member_checks_async.py,\
"""
2 changes: 1 addition & 1 deletion tests/checkers/unittest_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_xxx_without_space(self) -> None:

def test_xxx_middle(self) -> None:
code = """a = 1
# midle XXX
# middle XXX
"""
with self.assertNoMessages():
self.checker.process_tokens(_tokenize_str(code))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Check the behavior for unkonwn symbol/msgid
# Check the behavior for unknown symbol/msgid
# (Originally) reported in https://github.com/pylint-dev/pylint/pull/6293

[tool.pylint."messages control"]
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/functional/a/arguments_differ.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class ChildT3(ParentT3):
def func(self, user_input: FooT1) -> None:
pass

# Keyword and positional overriddes
# Keyword and positional overrides
class AbstractFoo:

def kwonly_1(self, first, *, second, third):
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/c/consider/consider_using_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
if 'key' in dictionary: # not accessing the dictionary in assignment
variable = "string"

if 'key' in dictionary: # is a match, but not obvious and we ignore it for now
if 'key' in dictionary: # is a match, but not obvious, and we ignore it for now
variable = dictionary[key]

if 'key1' in dictionary: # dictionary querried for wrong key
if 'key1' in dictionary: # dictionary queried for wrong key
variable = dictionary['key2']

if 'key' in dictionary: # body is not pure
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# pylint: disable=missing-module-docstring

dictionary = {'0': 0}
# quotes are inconsistent when targetting Python 3.12 (use single quotes)
# quotes are inconsistent when targeting Python 3.12 (use single quotes)
F_STRING = f'{dictionary["0"]}' # [inconsistent-quotes]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# pylint: disable=missing-module-docstring

dictionary = {'0': 0}
# quotes are consistent when targetting 3.11 and earlier (cannot use single quotes here)
# quotes are consistent when targeting 3.11 and earlier (cannot use single quotes here)
F_STRING = f'{dictionary["0"]}'
2 changes: 1 addition & 1 deletion tests/functional/m/misplaced_format_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
print("value: {}").format(123) # [misplaced-format-function]
print('value: {}'.format(123))
print('{} Come Forth!'.format('Lazarus'))
print('Der Hem ist mein Licht und mein Heil, vor wem sollte ich mich furchten? => {}'.format('Psalm 27, 1'))
print('He is my light and my salvation, of whom should I be afraid? => {}'.format('Psalm 27, 1'))
print('123')
print()
s = 'value: {}'.format(123)
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/n/names_in__all__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pylint: disable=too-few-public-methods, import-error, unnecessary-pass
"""Test Pylint's use of __all__.
* NonExistant is not defined in this module, and it is listed in
* NonExistent is not defined in this module, and it is listed in
__all__. An error is expected.
* This module imports path and republished it in __all__. No errors
Expand All @@ -16,7 +16,7 @@
'', # [undefined-all-variable]
Missing,
SomeUndefined, # [undefined-variable]
'NonExistant', # [undefined-all-variable]
'NonExistent', # [undefined-all-variable]
'path',
'func', # [undefined-all-variable]
'inner', # [undefined-all-variable]
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/n/names_in__all__.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
undefined-all-variable:16:4:16:6::Undefined variable name '' in __all__:UNDEFINED
undefined-variable:18:4:18:17::Undefined variable 'SomeUndefined':UNDEFINED
undefined-all-variable:19:4:19:17::Undefined variable name 'NonExistant' in __all__:UNDEFINED
undefined-all-variable:19:4:19:17::Undefined variable name 'NonExistent' in __all__:UNDEFINED
undefined-all-variable:21:4:21:10::Undefined variable name 'func' in __all__:UNDEFINED
undefined-all-variable:22:4:22:11::Undefined variable name 'inner' in __all__:UNDEFINED
undefined-all-variable:23:4:23:16::Undefined variable name 'InnerKlass' in __all__:UNDEFINED
4 changes: 2 additions & 2 deletions tests/functional/n/no/no_name_in_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
toto.yo()

from xml.etree import ElementTree
ElementTree.nonexistant_function() # [no-member]
ElementTree.another.nonexistant.function() # [no-member]
ElementTree.nonexistent_function() # [no-member]
ElementTree.another.nonexistent.function() # [no-member]


import sys
Expand Down
Loading

0 comments on commit 0950916

Please sign in to comment.