Skip to content

Short statement(s) to check python versions using unavailable syntax features

License

Notifications You must be signed in to change notification settings

afq984/syntaxguard

Repository files navigation

syntaxguard

Use syntax unavailable to unsupported Python versions to show a error message about Python version

The following won't show the python version hint when run with Python 2.7, because the code doesn't even parse, the check never runs:

import sys
import getpass

if sys.version_info < (3, 6):
    print('Please use Python 3.6 or later')
    sys.exit(1)


print(f'Hello, {getpass.getuser()}')

But this does:

f'Please use Python 3.6 or later'
import getpass

print(f'Hello, {getpass.getuser()}')

Example output:

$ python2 hello.py
  File "hello.py", line 1
    f'Please use Python 3.6 or later'
                                    ^
SyntaxError: invalid syntax

About

Short statement(s) to check python versions using unavailable syntax features

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages