Skip to content

Commit

Permalink
Remove unnecessary guards for non-falsey values (#259)
Browse files Browse the repository at this point in the history
The containers:

- CharSetGroupProber.probers
- EscCharSetProber.coding_sm

Never contain falsey values. Can remove the constant guard expressions.
  • Loading branch information
jdufresne committed Jun 27, 2022
1 parent e31c288 commit 9d620b2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
11 changes: 3 additions & 8 deletions chardet/charsetgroupprober.py
Expand Up @@ -40,10 +40,9 @@ def reset(self):
super().reset()
self._active_num = 0
for prober in self.probers:
if prober:
prober.reset()
prober.active = True
self._active_num += 1
prober.reset()
prober.active = True
self._active_num += 1
self._best_guess_prober = None

@property
Expand All @@ -64,8 +63,6 @@ def language(self):

def feed(self, byte_str):
for prober in self.probers:
if not prober:
continue
if not prober.active:
continue
state = prober.feed(byte_str)
Expand All @@ -92,8 +89,6 @@ def get_confidence(self):
best_conf = 0.0
self._best_guess_prober = None
for prober in self.probers:
if not prober:
continue
if not prober.active:
self.logger.debug("%s not active", prober.charset_name)
continue
Expand Down
4 changes: 1 addition & 3 deletions chardet/escprober.py
Expand Up @@ -62,8 +62,6 @@ def __init__(self, lang_filter=None):
def reset(self):
super().reset()
for coding_sm in self.coding_sm:
if not coding_sm:
continue
coding_sm.active = True
coding_sm.reset()
self.active_sm_count = len(self.coding_sm)
Expand All @@ -84,7 +82,7 @@ def get_confidence(self):
def feed(self, byte_str):
for c in byte_str:
for coding_sm in self.coding_sm:
if not coding_sm or not coding_sm.active:
if not coding_sm.active:
continue
coding_state = coding_sm.next_state(c)
if coding_state == MachineState.ERROR:
Expand Down

0 comments on commit 9d620b2

Please sign in to comment.