We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
We defined str in typeshed.
str
typeshed/stdlib/2and3/builtins.pyi
Lines 1522 to 1527 in f76b7b2
➜ cat t.py import ast text = input() try: ast.parse(text) except SyntaxError as e: print(e.text) ➜ echo 'max(1 for i in range(10), key=lambda x: x+1)' | python t.py None
Check from Python 3.7 source code. https://github.com/python/cpython/blob/c6b31061997526b31961ec34328408ca421f51fc/Python/ast.c#L681-L685
loc = PyErr_ProgramTextObject(c->c_filename, LINENO(n)); if (!loc) { Py_INCREF(Py_None); loc = Py_None; }
https://github.com/python/cpython/blob/c6b31061997526b31961ec34328408ca421f51fc/Python/errors.c#L1203-L1215
PyObject * PyErr_ProgramTextObject(PyObject *filename, int lineno) { FILE *fp; if (filename == NULL || lineno <= 0) return NULL; fp = _Py_fopen_obj(filename, "r" PY_STDIOTEXTMODE); if (fp == NULL) { PyErr_Clear(); return NULL; } return err_programtext(fp, lineno); }
let us make a special file to confirm
➜ echo 'for test' > \<unknown\> ➜ echo 'max(1 for i in range(10), key=lambda x: x+1)' | python t.py for test
The text was updated successfully, but these errors were encountered:
Thank you for the analysis, patches welcome!
Sorry, something went wrong.
Make SyntaxError.text be optional (#3119)
e2ec5d0
Closes #3118
Successfully merging a pull request may close this issue.
We defined
str
in typeshed.typeshed/stdlib/2and3/builtins.pyi
Lines 1522 to 1527 in f76b7b2
How to reproduce it
Analysis
Check from Python 3.7 source code.
https://github.com/python/cpython/blob/c6b31061997526b31961ec34328408ca421f51fc/Python/ast.c#L681-L685
https://github.com/python/cpython/blob/c6b31061997526b31961ec34328408ca421f51fc/Python/errors.c#L1203-L1215
let us make a special file to confirm
The text was updated successfully, but these errors were encountered: