Skip to content

Commit

Permalink
Fix some minor linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-blanchard committed Jun 24, 2022
1 parent e124802 commit c30a33f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
4 changes: 2 additions & 2 deletions chardet/charsetprober.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def reset(self):
def charset_name(self):
return None

def feed(self, buf):
pass
def feed(self, byte_str):
raise NotImplementedError

@property
def state(self):
Expand Down
4 changes: 2 additions & 2 deletions chardet/universaldetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def feed(self, byte_str):
if self.done:
return

if not len(byte_str):
if not byte_str:
return

if not isinstance(byte_str, bytearray):
Expand Down Expand Up @@ -193,7 +193,7 @@ def feed(self, byte_str):
if not self._utf1632_prober:
self._utf1632_prober = UTF1632Prober()

if self._utf1632_prober.state() == ProbingState.DETECTING:
if self._utf1632_prober.state == ProbingState.DETECTING:
if self._utf1632_prober.feed(byte_str) == ProbingState.FOUND_IT:
self.result = {
"encoding": self._utf1632_prober.charset_name,
Expand Down
16 changes: 5 additions & 11 deletions chardet/utf1632prober.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Jason Zavaglia
Expand All @@ -24,9 +18,8 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################
from chardet.enums import ProbingState

from .charsetprober import CharSetProber
from .enums import ProbingState


class UTF1632Prober(CharSetProber):
Expand Down Expand Up @@ -202,13 +195,14 @@ def feed(self, byte_str):
else:
self.nonzeros_at_mod[mod4] += 1
self.position += 1
return self.state()
return self.state

@property
def state(self):
if self._state in [ProbingState.NOT_ME, ProbingState.FOUND_IT]:
if self._state in {ProbingState.NOT_ME, ProbingState.FOUND_IT}:
# terminal, decided states
return self._state
elif self.get_confidence() > 0.80:
if self.get_confidence() > 0.80:
self._state = ProbingState.FOUND_IT
elif self.position > 4 * 1024:
# if we get to 4kb into the file, and we can't conclude it's UTF,
Expand Down

0 comments on commit c30a33f

Please sign in to comment.