diff --git a/captcha-old.py b/captcha-old.py index 34b71d8a1..db0f143db 100644 --- a/captcha-old.py +++ b/captcha-old.py @@ -40,12 +40,13 @@ try: from PIL import ImageDraw from PIL import ImageEnhance from PIL import ImageOps -except: +except ImportError: sys.exit( "This script requires the Python Imaging Library - http://www.pythonware.com/products/pil/" ) -nonalpha = re.compile("[^a-z]") # regex to test for suitability of words +# regex to test for suitability of words +nonalpha = re.compile("[^a-z]") # Pillow 9.2 added getbbox to replace getsize, and getsize() was removed in Pillow 10 # https://pillow.readthedocs.io/en/stable/releasenotes/10.0.0.html#font-size-and-offset-methods @@ -63,7 +64,7 @@ def wobbly_copy(src, wob, col, scale, ang): rot = src.rotate(rr, Image.BILINEAR) # Do a cheap bounding-box op here to try to limit work below bbx = rot.getbbox() - if bbx == None: + if bbx is None: return src else: l, t, r, b = bbx diff --git a/captcha.py b/captcha.py index 12a09af9b..c263e802b 100644 --- a/captcha.py +++ b/captcha.py @@ -40,15 +40,19 @@ try: from PIL import ImageDraw from PIL import ImageEnhance from PIL import ImageOps -except: +except ImportError: sys.exit( "This script requires the Python Imaging Library - http://www.pythonware.com/products/pil/" ) -nonalpha = re.compile("[^a-z]") # regex to test for suitability of words +# regex to test for suitability of words +nonalpha = re.compile("[^a-z]") + +# when il beside each other, hard to read confusedletters = re.compile( "[ijtlr][ijtl]|r[nompqr]|[il]" -) # when il beside each other, hard to read. +) + # Pillow 9.2 added getbbox to replace getsize, and getsize() was removed in Pillow 10 # https://pillow.readthedocs.io/en/stable/releasenotes/10.0.0.html#font-size-and-offset-methods # We don't have a requirements.txt, and therefore don't declare any specific supported or min version... @@ -65,7 +69,7 @@ def wobbly_copy(src, wob, col, scale, ang): rot = src.rotate(rr, Image.BILINEAR) # Do a cheap bounding-box op here to try to limit work below bbx = rot.getbbox() - if bbx == None: + if bbx is None: return src else: l, t, r, b = bbx diff --git a/tox.ini b/tox.ini index 5c445426f..d7bdab596 100644 --- a/tox.ini +++ b/tox.ini @@ -17,9 +17,7 @@ basepython = python3 [flake8] exclude = .tox max_line_length = 80 -; E128 continuation line under-indented for visual indent ; E501 line too long (X > 80 characters) -; E711 comparison to None should be 'if cond is None:' -; E722 do not use bare 'except' +; Deprecated best practice - https://www.flake8rules.com/rules/W503.html ; W503 line break before binary operator -ignore = E128,E501,E711,E722,W503 +ignore = E501,W503