autoconj icon indicating copy to clipboard operation
autoconj copied to clipboard

Python 3 compatibility

Open cclauss opened this issue 7 years ago • 0 comments

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.

  • F821: undefined name name
  • F822: undefined name name in __all__
  • F823: local variable name referenced before assignment
  • E901: SyntaxError or IndentationError
  • E999: SyntaxError -- failed to compile a file into an Abstract Syntax Tree

cclauss avatar Jan 24 '19 15:01 cclauss