Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recognise magic methods #81

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion flake8_spellcheck/python.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
abspath
abstractmethod
aenter
aexit
aiter
anext
arg
argparse
args
Expand Down Expand Up @@ -30,7 +34,6 @@ classmethod
cls
cmp
configparser
contextlib
contextmanager
ctypes
cwd
Expand All @@ -41,58 +44,87 @@ dateutil
dedent
deepcopy
defaultdict
delattr
delitem
dict
distutils
divmod
docstring
elif
endswith
enum
env
environ
eq
Copy link
Owner

Choose a reason for hiding this comment

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

Ideally we would only allow theses exclusively in the context of __ __. But right now there is no way to do that in flake8-spellcheck

Something for me to consider in the future :)

Copy link
Author

Choose a reason for hiding this comment

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

Yes - did think of that, especially the 2-letter names

I did some investigation, but not obvious how to achieve that

errno
expanduser
findall
flake8
floordiv
fnmatch
freezegun
fromisoformat
frozenset
functools
ge
getattr
getattribute
getcwd
getenv
getitem
getpass
gettext
getvalue
gt
gunicorn
hasattr
hashlib
hexdigest
iadd
iand
idiv
idivmod
ifloordiv
ilshift
imatmul
imod
importlib
imul
init
instancecheck
int
ior
ipow
irshift
isclass
isdigit
isdir
isinstance
isoformat
issubclass
isub
isupper
itemgetter
iter
iterable
iteritems
itertools
itervalues
itruediv
ixor
jinja
jinja2
json
kwarg
kwargs
le
libarchive
lrange
lshift
lstrip
lt
makedirs
matmul
maxsize
md5
mimetype
Expand All @@ -103,16 +135,19 @@ mkstemp
mktime
monkeypatch
mtime
mul
mypy
namedtuple
nargs
ne
netloc
noqa
optionxform
optparse
parametrize
pathlib
pkgutil
pos
posixpath
pprint
pragma
Expand All @@ -125,20 +160,37 @@ python2
python3
pytz
qsl
radd
rand
randint
randrange
rdiv
rdivmod
readlines
realpath
relpath
repr
returncode
rfloordiv
rlshift
rmatmul
rmod
rmtree
rmul
ror
rpow
rrshift
rshift
rsplit
rstrip
rsub
rtruediv
runtime
rxor
scandir
setattr
setdefault
setitem
setuptools
shutil
sizeof
Expand All @@ -149,13 +201,16 @@ str
strftime
strptime
struct
subclasscheck
subprocess
sys
tarfile
tempfile
textwrap
timedelta
traceback
truediv
trunc
tzinfo
tzname
urlencode
Expand Down
117 changes: 117 additions & 0 deletions tests/test_flake8_spellcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,3 +576,120 @@ def my_view(request):
result = flake8_path.run_flake8(["--dictionaries=python,technical,django,en_US"])
assert result.exit_code == 0
assert result.out_lines == []


def test_magic_methods(flake8_path):
(flake8_path / "example.py").write_text(
dedent(
"""
# Class to contain all known magic method names, as at Python 3.10
# https://docs.python.org/3/reference/datamodel.html#special-method-names
class MagicMethods:
def __new__(cls): pass
def __init__(self): pass
def __del__(self): pass
def __repr__(self): pass
def __str__(self): pass
def __bytes__(self): pass
def __format__(self): pass
def __lt__(self): pass
def __le__(self): pass
def __eq__(self): pass
def __ne__(self): pass
def __gt__(self): pass
def __ge__(self): pass
def __hash__(self): pass
def __bool__(self): pass
def __getattr__(self): pass
def __getattribute__(self): pass
def __setattr__(self): pass
def __delattr__(self): pass
def __dir__(self): pass
def __get__(self): pass
def __set__(self): pass
def __delete__(self): pass
def __slots__(self): pass
def __init_subclass__(cls): pass
def __set_name__(self): pass
def __prepare__(self): pass
def __instancecheck__(self): pass
def __subclasscheck__(self): pass
def __class_getitem__(cls): pass
def __call__(self): pass
def __len__(self): pass
def __length_hint__(self): pass
def __getitem__(self): pass
def __setitem__(self): pass
def __delitem__(self): pass
def __missing__(self): pass
def __iter__(self): pass
def __reversed__(self): pass
def __contains__(self): pass
def __add__(self): pass
def __sub__(self): pass
def __mul__(self): pass
def __matmul__(self): pass
def __truediv__(self): pass
def __floordiv__(self): pass
def __mod__(self): pass
def __divmod__(self): pass
def __pow__(self): pass
def __lshift__(self): pass
def __rshift__(self): pass
def __and__(self): pass
def __xor__(self): pass
def __or__(self): pass
def __radd__(self): pass
def __rsub__(self): pass
def __rmul__(self): pass
def __rmatmul__(self): pass
def __rtruediv__(self): pass
def __rfloordiv__(self): pass
def __rmod__(self): pass
def __rdivmod__(self): pass
def __rpow__(self): pass
def __rlshift__(self): pass
def __rrshift__(self): pass
def __rand__(self): pass
def __rxor__(self): pass
def __ror__(self): pass
def __iadd__(self): pass
def __isub__(self): pass
def __imul__(self): pass
def __imatmul__(self): pass
def __itruediv__(self): pass
def __ifloordiv__(self): pass
def __imod__(self): pass
def __idivmod__(self): pass
def __ipow__(self): pass
def __ilshift__(self): pass
def __irshift__(self): pass
def __iand__(self): pass
def __ixor__(self): pass
def __ior__(self): pass
def __neg__(self): pass
def __pos__(self): pass
def __abs__(self): pass
def __invert__(self): pass
def __complex__(self): pass
def __int__(self): pass
def __float__(self): pass
def __index__(self): pass
def __round__(self): pass
def __trunc__(self): pass
def __floor__(self): pass
def __ceil__(self): pass
def __coerce__(self): pass
def __enter__(self): pass
def __exit__(self): pass
def __match_args__(self): pass
def __await__(self): pass
def __aiter__(self): pass
def __anext__(self): pass
def __aenter__(self): pass
def __aexit__(self): pass
"""
)
)
result = flake8_path.run_flake8()
assert result.out_lines == []