Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.8 test error: AttributeError: 'Constant' object has no attribute 'n' #47

Closed
hroncok opened this issue Apr 11, 2019 · 3 comments · Fixed by #49
Closed

Python 3.8 test error: AttributeError: 'Constant' object has no attribute 'n' #47

hroncok opened this issue Apr 11, 2019 · 3 comments · Fixed by #49

Comments

@hroncok
Copy link

hroncok commented Apr 11, 2019

This is Python 3.8.0a3. I had to modify the tox.ini to have basepython set for 3.8:

diff --git a/tox.ini b/tox.ini
index c81ac77..f40958d 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,6 +1,6 @@
 [tox]
 envlist =
-    py27,py33,py34,py35,py36,py37,pypy,
+    py27,py33,py34,py35,py36,py37,py38,pypy,
     docs,{py2,py3}-cover,coverage
 skip_missing_interpreters = True
 
@@ -14,6 +14,7 @@ basepython =
     py35: python3.5
     py36: python3.6
     py37: python3.7
+    py38: python3.8
     pypy: pypy
     py2: python2.7
     py3: python3.5

And when i run tox for 3.8 on master (333986c):

$ tox -e py38
GLOB sdist-make: .../pyramid_mako/setup.py
py38 inst-nodeps: .../pyramid_mako/.tox/.tmp/package/1/pyramid_mako-1.0.3.dev0.zip
py38 installed: beautifulsoup4==4.7.1,coverage==4.5.3,hupper==1.6.1,Mako==1.0.8,MarkupSafe==1.1.1,nose==1.3.7,PasteDeploy==2.0.1,plaster==1.0,plaster-pastedeploy==0.6,pyramid==1.10.2,pyramid-mako==1.0.3.dev0,six==1.12.0,soupsieve==1.9,translationstring==1.3,venusian==1.2.0,waitress==1.2.1,WebOb==1.8.5,WebTest==2.0.33,zope.deprecation==4.4.0,zope.interface==4.6.0
py38 run-test-pre: PYTHONHASHSEED='1721400932'
py38 runtests: commands[0] | pip install 'pyramid_mako[testing]'
Requirement already satisfied: pyramid_mako[testing] in ./.tox/py38/lib/python3.8/site-packages (1.0.3.dev0)
Requirement already satisfied: Mako>=0.8 in ./.tox/py38/lib/python3.8/site-packages (from pyramid_mako[testing]) (1.0.8)
Requirement already satisfied: pyramid in ./.tox/py38/lib/python3.8/site-packages (from pyramid_mako[testing]) (1.10.2)
Requirement already satisfied: nose; extra == "testing" in ./.tox/py38/lib/python3.8/site-packages (from pyramid_mako[testing]) (1.3.7)
Requirement already satisfied: WebTest>=1.3.1; extra == "testing" in ./.tox/py38/lib/python3.8/site-packages (from pyramid_mako[testing]) (2.0.33)
Requirement already satisfied: coverage; extra == "testing" in ./.tox/py38/lib/python3.8/site-packages (from pyramid_mako[testing]) (4.5.3)
Requirement already satisfied: MarkupSafe>=0.9.2 in ./.tox/py38/lib/python3.8/site-packages (from Mako>=0.8->pyramid_mako[testing]) (1.1.1)
Requirement already satisfied: zope.interface>=3.8.0 in ./.tox/py38/lib/python3.8/site-packages (from pyramid->pyramid_mako[testing]) (4.6.0)
Requirement already satisfied: plaster in ./.tox/py38/lib/python3.8/site-packages (from pyramid->pyramid_mako[testing]) (1.0)
Requirement already satisfied: plaster-pastedeploy in ./.tox/py38/lib/python3.8/site-packages (from pyramid->pyramid_mako[testing]) (0.6)
Requirement already satisfied: zope.deprecation>=3.5.0 in ./.tox/py38/lib/python3.8/site-packages (from pyramid->pyramid_mako[testing]) (4.4.0)
Requirement already satisfied: translationstring>=0.4 in ./.tox/py38/lib/python3.8/site-packages (from pyramid->pyramid_mako[testing]) (1.3)
Requirement already satisfied: venusian>=1.0 in ./.tox/py38/lib/python3.8/site-packages (from pyramid->pyramid_mako[testing]) (1.2.0)
Requirement already satisfied: hupper in ./.tox/py38/lib/python3.8/site-packages (from pyramid->pyramid_mako[testing]) (1.6.1)
Requirement already satisfied: webob>=1.8.3 in ./.tox/py38/lib/python3.8/site-packages (from pyramid->pyramid_mako[testing]) (1.8.5)
Requirement already satisfied: setuptools in ./.tox/py38/lib/python3.8/site-packages (from pyramid->pyramid_mako[testing]) (41.0.0)
Requirement already satisfied: beautifulsoup4 in ./.tox/py38/lib/python3.8/site-packages (from WebTest>=1.3.1; extra == "testing"->pyramid_mako[testing]) (4.7.1)
Requirement already satisfied: six in ./.tox/py38/lib/python3.8/site-packages (from WebTest>=1.3.1; extra == "testing"->pyramid_mako[testing]) (1.12.0)
Requirement already satisfied: waitress>=0.8.5 in ./.tox/py38/lib/python3.8/site-packages (from WebTest>=1.3.1; extra == "testing"->pyramid_mako[testing]) (1.2.1)
Requirement already satisfied: PasteDeploy>=1.5.0 in ./.tox/py38/lib/python3.8/site-packages (from plaster-pastedeploy->pyramid->pyramid_mako[testing]) (2.0.1)
Requirement already satisfied: soupsieve>=1.2 in ./.tox/py38/lib/python3.8/site-packages (from beautifulsoup4->WebTest>=1.3.1; extra == "testing"->pyramid_mako[testing]) (1.9)
py38 runtests: commands[1] | nosetests --with-xunit --xunit-file=nosetests-py38.xml
.E..............................................................................
======================================================================
ERROR: test_call_render_raises (pyramid_mako.tests.MakoLookupTemplateRendererTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File ".../pyramid_mako/pyramid_mako/__init__.py", line 148, in __call__
    result = template.render_unicode(**system)
  File ".../pyramid_mako/pyramid_mako/tests.py", line 665, in render_unicode
    raise self.render_exc
NotImplementedError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".../pyramid_mako/pyramid_mako/tests.py", line 364, in test_call_render_raises
    instance({}, {})
  File ".../pyramid_mako/pyramid_mako/__init__.py", line 152, in __call__
    errtext = text_error_template().render(
  File ".../pyramid_mako/.tox/py38/lib/python3.8/site-packages/mako/exceptions.py", line 236, in text_error_template
    return mako.template.Template(r"""
  File ".../pyramid_mako/.tox/py38/lib/python3.8/site-packages/mako/template.py", line 320, in __init__
    (code, module) = _compile_text(self, text, filename)
  File ".../pyramid_mako/.tox/py38/lib/python3.8/site-packages/mako/template.py", line 704, in _compile_text
    source, lexer = _compile(template, text, filename,
  File ".../pyramid_mako/.tox/py38/lib/python3.8/site-packages/mako/template.py", line 686, in _compile
    source = codegen.compile(node,
  File ".../pyramid_mako/.tox/py38/lib/python3.8/site-packages/mako/codegen.py", line 52, in compile
    _GenerateRenderMethod(printer,
  File ".../pyramid_mako/.tox/py38/lib/python3.8/site-packages/mako/codegen.py", line 127, in __init__
    args = pagetag.body_decl.get_argument_expressions()
  File ".../pyramid_mako/.tox/py38/lib/python3.8/site-packages/mako/ast.py", line 175, in get_argument_expressions
    name, pyparser.ExpressionGenerator(default).value()))
  File ".../pyramid_mako/.tox/py38/lib/python3.8/site-packages/mako/pyparser.py", line 230, in __init__
    self.generator.visit(astnode)
  File ".../pyramid_mako/.tox/py38/lib/python3.8/site-packages/mako/_ast_util.py", line 279, in visit
    return f(node)
  File ".../pyramid_mako/.tox/py38/lib/python3.8/site-packages/mako/_ast_util.py", line 685, in visit_Constant
    self.write(repr(node.n))
AttributeError: 'Constant' object has no attribute 'n'

----------------------------------------------------------------------
Ran 80 tests in 0.367s

FAILED (errors=1)
ERROR: InvocationError for command '.../pyramid_mako/.tox/py38/bin/nosetests --with-xunit --xunit-file=nosetests-py38.xml' (exited with code 1)
___________________________________ summary ____________________________________
ERROR:   py38: commands failed
@stevepiercy
Copy link
Member

The bug mentioned in sqlalchemy/mako#287 got released in mako 1.0.8.

If you have a fix for pyramid_mako, please submit a PR.

See also the open issue #44 and PR #46.

@hroncok
Copy link
Author

hroncok commented Apr 11, 2019

I think I know what the problem is (in mako).

EDIT: See sqlalchemy/mako#287 (comment)

hroncok added a commit to hroncok/mako that referenced this issue Apr 11, 2019
Since Python 3.8, class ast.Constant is used for all constants.
Old classes ast.Num, ast.Str, ast.Bytes, ast.NameConstant and
ast.Ellipsis are still available, but they will be removed in
future Python releases.

Constants have values, but not always ns.

See sqlalchemy#287 (comment)
See python/cpython#9445
Fixes Pylons/pyramid_mako#47
@hroncok
Copy link
Author

hroncok commented Apr 11, 2019

sqlalchemy/mako#292

sqlalchemy-bot pushed a commit to sqlalchemy/mako that referenced this issue Apr 13, 2019
Since Python 3.8, class ast.Constant is used for all constants.
Old classes ast.Num, ast.Str, ast.Bytes, ast.NameConstant and
ast.Ellipsis are still available, but they will be removed in
future Python releases.

Further corrected the previous fix for 🎫`287` as it relied upon
an attribute that is monkeypatched by Python's ``ast`` module for some
reason, which fails if ``ast`` hasn't been imported; the correct
attribute ``Constant.value`` is now used.   Also note the issue
was mis-numbered in the previous changelog note.

References: Pylons/pyramid_mako#47

Fixes: #287
Closes: #292
Pull-request: #292
Pull-request-sha: b48081a

Change-Id: Ic3fd1975e608b6890410f3fd4ad4d949478dc45e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants