Fork of Python 2.7 with new syntax, builtins, and libraries backported from Python 3.
Python C Assembly Shell Makefile TeX Other
Latest commit 736faed May 19, 2017 @naftaliharris naftaliharris Merge pull request #80 from stefantalpalaru/markdown
fix the GitHub Markdown
Permalink
Failed to load latest commit information.
Demo Merge commit '803e6ca3cef2dfdd90298d8a11e57fc559317ea5' into merge_2.… Dec 22, 2016
Doc Merge commit '803e6ca3cef2dfdd90298d8a11e57fc559317ea5' into merge_2.… Dec 22, 2016
Grammar Define our own "NONLOCAL" token Dec 31, 2016
Include Implements PEP 628, (tau in math module) Feb 2, 2017
Lib Miscellaneous Python -> Tauthon Feb 24, 2017
Mac Issue #28440: No longer add /Library/Python/site-packages, the Apple-… Dec 3, 2016
Misc Merge commit '803e6ca3cef2dfdd90298d8a11e57fc559317ea5' into merge_2.… Dec 22, 2016
Modules Changes binary name to tauthon Feb 23, 2017
Objects Merge commit '803e6ca3cef2dfdd90298d8a11e57fc559317ea5' into merge_2.… Dec 22, 2016
PC Fix PC/VS9.0/build_ssl.py for recent OpenSSL Nov 7, 2016
PCbuild Issue #28248: Update Windows build to use OpenSSL 1.0.2j Oct 11, 2016
Parser The token following nonlocal must be a NAME Dec 31, 2016
Python Commit f4136c2; deleting free variables in nested blocks. Jan 4, 2017
RISCOS Issue #28139: Fix messed up indentation Sep 17, 2016
Tools Merge commit '803e6ca3cef2dfdd90298d8a11e57fc559317ea5' into merge_2.… Dec 22, 2016
.bzrignore Issue #25899: Fixed typo in .bzrignore. Dec 18, 2015
.gitignore gitignore improvements from python3 Nov 8, 2015
.hgeol Issue #27888: Prevent Windows installer from displaying console windo… Sep 1, 2016
.hgignore Issue #25925: Backport C coverage reporting Makefile targets Jan 20, 2016
.travis.yml Rerun broken tests in verbose mode. Dec 1, 2016
LICENSE Miscellaneous Python -> Tauthon Feb 24, 2017
Makefile.pre.in Changes binary name to tauthon Feb 23, 2017
README Updated old readme to point for Tauthon Feb 24, 2017
README.md fix the GitHub Markdown May 19, 2017
aclocal.m4 assume egd unless OPENSSL_NO_EGD is defined—remove configure check (c… Jul 7, 2016
config.guess - Import latest config.sub config.guess files Dec 1, 2016
config.sub - Import latest config.sub config.guess files Dec 1, 2016
configure Merge commit '803e6ca3cef2dfdd90298d8a11e57fc559317ea5' into merge_2.… Dec 22, 2016
configure.ac Merge commit '803e6ca3cef2dfdd90298d8a11e57fc559317ea5' into merge_2.… Dec 22, 2016
install-sh Patch #746366: Update to current automake install-sh. Will backport t… Jun 14, 2003
pyconfig.h.in assume egd unless OPENSSL_NO_EGD is defined—remove configure check (c… Jul 7, 2016
setup.py Issue #26661: setup.py now detects system libffi with multiarch wrapper. Sep 18, 2016

README.md

Tauthon

Tauthon is a backwards-compatible fork of the Python 2.7.13 interpreter with new syntax, builtins, and libraries backported from Python 3.x. Python code and C-extensions targeting Python 2.7 or below are expected to run unmodified on Tauthon and produce the same output. But with Tauthon, that code can now use some of the new features from Python 3.x.

Build Status

What's new in Tauthon

  • Function Annotations

    >>> def f(a:int, b:str) -> list:
    ...     pass
    ...
    >>> f.__annotations__
    {'a': <type 'int'>, 'b': <type 'str'>, 'return': <type 'list'>}

    More info: PEP 3107

  • Keyword-Only Arguments

    >>> def f(a, *, b):
    ...     pass
    ...
    >>> f(1, 2)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: f() takes exactly 1 positional argument (2 given)
    >>> f(1, b=2)
    >>>

    More info: PEP 3102

  • "async" and "await" Syntax

    >>> import types
    >>> @types.coroutine
    ... def delayed_print():
    ...     printme = yield
    ...     print printme
    ...
    >>> async def main():
    ...     while True:
    ...         await delayed_print()
    ...
    >>> coro = main()
    >>> coro.send(None)
    >>> coro.send("hello")
    hello
    >>> coro.send("there")
    there
    >>> coro.send("friend")
    friend

    More info: PEP 492, Tutorial

  • Argument-less "super"

    >>> class MyList(list):
    ...     def __repr__(self):
    ...             return "MyList" + super().__repr__()
    ...
    >>> MyList(range(3))
    MyList[0, 1, 2]

    More info: PEP 3135, API Docs

  • New Metaclass Syntax

    >>> from collections import OrderedDict
    >>> class Meta(type):
    ...     @staticmethod
    ...     def __prepare__(name, bases, **kwds):
    ...             return OrderedDict()
    ...     def __new__(cls, name, bases, namespace, **kwds):
    ...             namespace.update(kwds)
    ...             res = type.__new__(cls, name, bases, dict(namespace))
    ...             res._namespace = namespace
    ...             return res
    ...     def __init__(*args, **kwds):
    ...             pass
    ...
    >>> class MyClass(metaclass=Meta, foo="bar"):
    ...     def first(self): pass
    ...     def second(self): pass
    ...     def third(self): pass
    ...
    >>> MyClass.foo
    'bar'
    >>> MyClass._namespace
    OrderedDict([('__module__', '__main__'), ('first', <function first at 0x1007ef568>), ('second', <function second at 0x10131b060>), ('third', <function third at 0x10131b118>), ('foo', 'bar')])

    More info: PEP 3115, Introduction to Metaclasses (in Python 2.x), API Docs (Python 3.x)

  • "nonlocal"

    >>> x = 0
    >>> def f():
    ...     x = 1
    ...     def g():
    ...         nonlocal x
    ...         x = 2
    ...     print x
    ...     g()
    ...     print x
    ...
    >>> print x; f(); print x
    0
    1
    2
    0
    >>> nonlocal = True; print nonlocal
    True

    Caveat: As you can see, to maintain backwards compatibility nonlocal is not a keyword, unlike in Python 3.x. So it can still be used as an identifier.

    More info: PEP 3104, API Docs

  • "yield from" Syntax

    >>> def generator():
    ...     yield from range(3)
    ...     yield from ['a', 'b', 'c']
    ...
    >>> [x for x in generator()]
    [0, 1, 2, 'a', 'b', 'c']

    More info: PEP 380

  • "typing" Module

    >>> from typing import List, Dict
    >>> List[Dict[str, int]]
    typing.List[typing.Dict[str, int]]
    >>> def wordcount(words:List[str]) -> Dict[str, int]:
    ...     return collections.Counter(words)

    More info: PEP 483, PEP 484, API Docs

  • Function Signatures in "inspect"

    >>> import inspect
    >>> def f(a:int, b, *args, c:str="foo", **kwds) -> list: pass
    ...
    >>> inspect.signature(f)
    <Signature (a:int, b, *args, c:str='foo', **kwds) -> list>
    >>> inspect.signature(f).parameters['c'].default
    'foo'

    More info: PEP 362, API Docs

  • Matrix Multiplication Operator

    >>> import numpy as np
    >>> class Matrix(np.matrix):
    ...     def __matmul__(self, other):
    ...         return np.dot(self, other)
    ...
    >>> X = Matrix([[1, 2], [3, 4]])
    >>> Y = Matrix([[4, 3], [2, 1]])
    >>> print X
    [[1 2]
     [3 4]]
    >>> print Y
    [[4 3]
     [2 1]]
    >>> print X @ Y
    [[ 8  5]
     [20 13]]
    >>> X @= Y
    >>> X
    matrix([[ 8,  5],
            [20, 13]])

    More info: PEP 465

  • Fine-grained OSErrors

    >>> open("not a file")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    IOError: [Errno 2] No such file or directory: 'not a file'
    >>> try:
    ...     open("not a file")
    ... except FileNotFoundError:
    ...     pass
    ...
    >>>

    Caveat: As you can see from the example, to maintain full backwards compatibility Tauthon does not raise these new OSErrors. Rather it gives you fine-grained OSErrors that you can catch them with, as an alternative to checking errno.

    More info: PEP 3151, API Docs

  • Underscores in Numeric Literals

    >>> 1_234_567
    1234567
    >>> 0xBEEF_CAFE
    3203386110
    >>> 0b1111_0000
    240
    >>>

    More info: PEP 515

  • "concurrent.futures" Module

    >>> from concurrent.futures import ThreadPoolExecutor
    >>> from datetime import datetime
    >>> import time
    >>> def snooze(seconds):
    ...     print "It's now %s, snoozing for %d seconds." % (datetime.now(), seconds)
    ...     time.sleep(seconds)
    ...     print "BEEP BEEP BEEP it's %s, time to get up!" % datetime.now()
    ...
    >>> def snooze_again(future):
    ...     print "Going back to sleep"
    ...     snooze(3)
    ...
    >>> pool = ThreadPoolExecutor()
    >>> future = pool.submit(snooze, 60)
    It's now 2016-11-17 12:09:41.822658, snoozing for 60 seconds.
    >>> print future
    <Future at 0x1040b7b10 state=running>
    >>> future.add_done_callback(snooze_again)
    >>> print datetime.now()
    2016-11-17 12:10:11.189143
    >>> BEEP BEEP BEEP it's 2016-11-17 12:10:41.824054, time to get up!
    Going back to sleep
    It's now 2016-11-17 12:10:41.824206, snoozing for 3 seconds.
    BEEP BEEP BEEP it's 2016-11-17 12:10:44.829196, time to get up!

    More info: PEP 3148, API Docs

  • "types.MappingProxyType"

    >>> import types
    >>> original = {'a': 1}
    >>> read_only_view = types.MappingProxyType(original)
    >>> read_only_view['a']
    1
    >>> read_only_view['b'] = 2
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: 'dict_proxy' object does not support item assignment
    >>> original['c'] = 3
    >>> original
    {'a': 1, 'c': 3}
    >>> read_only_view['c']
    3

    More info: API Docs

  • "selectors" Module

    >>> import selectors

    More info: API Docs

Building and Installation

Linux:

$ ./configure
$ make

OSX:

$ brew install openssl xz
$ CPPFLAGS="-I$(brew --prefix openssl)/include" LDFLAGS="-L$(brew --prefix openssl)/lib" MACOSX_DEPLOYMENT_TARGET=10.6 ./configure
$ make

You can then run Tauthon with ./python or ./python.exe.

Install with

$ make install

Backwards-incompatibilities

There are a small handful of backwards incompatibilities introduced by Tauthon. Triggering these involves checking the python version, introspection of Python internals (including the AST), or depending on errors being raised from nonexistent new features.

License

Tauthon is licensed under the Python Software License, (see the LICENSE file for details). This is not an official Python release; see PEP 404.