Improved type check in statistics.py. mypy check added in travis configuration file.

This commit is contained in:
Cédric Bonhomme 2017-05-05 11:07:09 +02:00
parent 98682932b5
commit 4122358571
No known key found for this signature in database
GPG key ID: A1CB94DE57B7A70D
2 changed files with 7 additions and 5 deletions

View file

@ -9,6 +9,7 @@ install:
script: script:
- nosetests --with-coverage --cover-package=stegano - nosetests --with-coverage --cover-package=stegano
- mypy --ignore-missing-imports --follow-imports skip --check-untyped-defs stegano/
after_success: after_success:
- coveralls - coveralls

View file

@ -37,16 +37,17 @@ def steganalyse(img):
""" """
encoded = img.copy() encoded = img.copy()
width, height = img.size width, height = img.size
colours = Counter() colours_counter = Counter() # type: Counter[int]
for row in range(height): for row in range(height):
for col in range(width): for col in range(width):
r, g, b = img.getpixel((col, row)) r, g, b = img.getpixel((col, row))
colours[r] += 1 colours_counter[r] += 1
most_common = colours.most_common(10) most_common = colours_counter.most_common(10)
dict_colours = OrderedDict(sorted(list(colours.items()), key=lambda t: t[1])) dict_colours = OrderedDict(sorted(list(colours_counter.items()),
key=lambda t: t[1]))
colours = 0 colours = 0 # type: float
for colour in list(dict_colours.keys()): for colour in list(dict_colours.keys()):
colours += colour colours += colour
colours = colours / len(dict_colours) colours = colours / len(dict_colours)