Where is the "from __future__ import braces" code?

PythonPython 2.7Python Internals

Python Problem Overview


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

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

so, since python is open-sourced I opened C:\Python27\Lib\__future__.py and looked. surprisingly, I found nothing there that handle importing braces module.

so, my question is, where is the code that handle this? what happen when I run that command?

Python Solutions


Solution 1 - Python

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;
  }

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionElishaView Question on Stackoverflow
Solution 1 - PythonPeter de RivazView Answer on Stackoverflow