pythononwheels / pow_devel

development repo for PyhtonOnWheels framework
www.pythononwheels.org
MIT License
75 stars 10 forks source link

Invalid Python comparison operator syntax used in auto-generated ../lib/application.py #47

Closed pikkelnut closed 3 years ago

pikkelnut commented 3 years ago

Immediately after generating a brand new application using the generate_app command, the new application Tornado server server.py script fails to run due to a syntax error in the auto-generated lib/application.py script. It is evident that there is a syntax error in the auto-generated script as this is an invalid Python statement.

Here is the output

(sharept_env) myusr@mydesktop:~/scripts/python/web/app/app$ python server.py
Traceback (most recent call last):
  File "server.py", line 16, in <module>
    from app.lib.application import Application, log_handler
  File "/home/myusr/scripts/python/web/app/app/lib/application.py", line 96
    if current_role :=  required_role != "any" and self.current_user.role != required_role:
                     ^
SyntaxError: invalid syntax

Line 96 should probably be changed to:

if required_role != "any" and self.current_user.role != required_role:

The above modification does allow the web server to start up. I just installed pythononwheels 0.925.1 only a few minutes ago (testing out your app). Unfortunately, as-is and without the above modification, this bug makes running a brand new application impossible. My Python version is 3.7.9, but this seems to be irrelevant as the issue is not version-related, rather a syntax issue. Thank you for looking into this problem. This bug must have been introduced in a recent commit, as this would prevent any new user from running a newly-created application no matter the Python version or platform.

pythononwheels commented 3 years ago

Hi @pikkelnut ayayay...thanks for the feedback. Yes, right, this was introduced in a new commit, The new released version uses the "walrus" operator which only works in python > 3.8.

It is definetly a good Idea to put this in python version dependant wrapper. So if < 3.8.0: use the classic comparision if python > 3.8.0 use walrus.

I will fix this and release an adapted version now.

Thank you !

pikkelnut commented 3 years ago

Thanks for the fix. Good to know on my part as I have not delved into Python 3.8+ so I was not aware of that walrus operator that was introduced. Upon reviewing that new comparison operator, it certainly makes comparisons more succinct.

pythononwheels commented 3 years ago

Hi @pikkelnut

Version: 0.925.5 is out fixing the problem with the unhandled walrus operator for python versions < 3.8 using your suggestion, since the current_role was actually not used in the decorator.

Tests with python 3.7.9 (as an example below 3.8) run fine now:

pow_09252_testresult_python_379

Thanks again for pointing me at this. Probably now I get a free: „runs on my machine“ shirt at last ;)