Skip to content

Commit

Permalink
cpu_rec.py (#13): make check on line 534 an equality check
Browse files Browse the repository at this point in the history
Python 3.8 prints a syntax warning when an identity check is used with a
literal. Using identity comparisons can lead to unexpected behavior.
See: https://adamj.eu/tech/2020/01/21/why-does-python-3-8-syntaxwarning-for-is-literal/
  • Loading branch information
sterzy committed Jun 13, 2021
1 parent 3f0f013 commit c590566
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion cpu_rec.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ def __init__(self, training, length=2, modulo=None, FreqVariant='A'):
self.tbl_size = 0x100**length
if length == 2 and modulo is None:
self.count = self.count_bigrams
elif length == 2 and modulo is 4:
elif length == 2 and modulo == 4:
self.count = self.count_bigrams_mod4
elif length == 3:
self.count = self.count_trigrams
Expand Down

2 comments on commit c590566

@jevinskie
Copy link

Choose a reason for hiding this comment

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

FYI I also had to perform the same fix to use PyPy. Mainline should now work fine with PyPy for a big speed improvement. Thanks!

@LRGH
Copy link
Collaborator

@LRGH LRGH commented on c590566 Jul 26, 2021

Choose a reason for hiding this comment

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

It is interesting that you mention that cpu_rec is much faster with PyPy. I will investigate this to see if it leads to ideas on how to improve its performance with CPython.

Please sign in to comment.