google-research / autoconj

Recognizing and exploiting conjugacy without a domain-specific language
Apache License 2.0
36 stars 7 forks source link

Python 3 compatibility #2

Open cclauss opened 5 years ago

cclauss commented 5 years ago

In Python 3:

  1. parens are not allowed around lambda parameters
  2. apply was removed from the language
  3. reduce was moved into functools to encourage the use of comprehensions instead

flake8 testing of https://github.com/google-research/autoconj on Python 3.7.1

$ flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics

./autoconj/conjugacy.py:250:28: E999 SyntaxError: invalid syntax
  make_mean_init = (lambda (i, normalizer): lambda scale=1.:
                           ^
./autoconj/tracers.py:388:18: F821 undefined name 'apply'
  fun.fmap_out = apply
                 ^
./autoconj/tracers.py:516:10: F821 undefined name 'reduce'
  return reduce(np.add, args)
         ^
./autoconj/matchers.py:89:25: F821 undefined name 'reduce'
def _set(*elts): return reduce(operator.or_, map(_singleton, elts))
                        ^
./autoconj/matchers.py:248:51: F821 undefined name 'list_patterns'
    lambda pat: match_list(*map(make_combinators, list_patterns(pat))))
                                                  ^
./examples/mixture_of_gaussians_variational.py:123:46: F821 undefined name 'itr'
    plt.savefig('/tmp/gmm_{:04d}.png'.format(itr))
                                             ^
./examples/mixture_of_gaussians_variational_tensorflow.py:129:46: F821 undefined name 'itr'
    plt.savefig('/tmp/gmm_{:04d}.png'.format(itr))
                                             ^
1     E999 SyntaxError: invalid syntax
6     F821 undefined name 'reduce'
7

E901,E999,F821,F822,F823 are the "showstopper" flake8 issues that can halt the runtime with a SyntaxError, NameError, etc. These 5 are different from most other flake8 issues which are merely "style violations" -- useful for readability but they do not effect runtime safety.