Python – Where is ‘from __future__ import braces’ Code

pythonpython-2.7python-internals

I was wondering what is exactly the code that gets executed on the command:

>>> from __future__ import braces
SyntaxError: not a chance

Since Python is open-sourced, I opened C:\Python27\Lib\__future__.py and looked.
Surprisingly, I found nothing there that handles importing the braces module.

So, my question is, where is the code that handles this? What happens when I run that command?

Best Answer

The code is in future.c:

future_check_features(PyFutureFeatures *ff, stmt_ty s, const char *filename)
...
  else if (strcmp(feature, "braces") == 0) {
    PyErr_SetString(PyExc_SyntaxError,
        "not a chance");
    PyErr_SyntaxLocation(filename, s->lineno);
    return 0;
  }