8000 gh-102856: Python tokenizer implementation for PEP 701 by mgmacias95 · Pull Request #104323 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-102856: Python tokenizer implementation for PEP 701 #104323

New issue

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

Merged
merged 20 commits into from
May 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use IA to clean code
  • Loading branch information
pablogsal committed May 18, 2023
commit b5ccd94e10a2d680b058cbbeb37128a12b42d356
8000
37 changes: 22 additions & 15 deletions Python/Python-tokenize.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,38 +118,45 @@ _tokenizer_error(struct tok_state *tok)
msg = "unknown tokenization error";
}

// TODO: Clean up this code and factor out common error paths

PyObject* errstr = NULL;
PyObject* error_line = NULL;
PyObject* tmp = NULL;
PyObject* value = NULL;
int result = 0;

Py_ssize_t size = tok->inp - tok->buf;
error_line = PyUnicode_DecodeUTF8(tok->buf, size, "replace");
if (!error_line) {
goto error;
result = -1;
goto exit;
}
PyObject *tmp = Py_BuildValue("(OnnOii)", tok->filename, tok->lineno, 0, error_line, 0, 0);

tmp = Py_BuildValue("(OnnOii)", tok->filename, tok->lineno, 0, error_line, 0, 0);
if (!tmp) {
goto error;
result = -1;
goto exit;
}
Py_CLEAR(error_line);

errstr = PyUnicode_FromString(msg);
if (!errstr) {
goto error;
result = -1;
goto exit;
}
PyObject* value = PyTuple_Pack(2, errstr, tmp);
Py_DECREF(errstr);
Py_DECREF(tmp);

value = PyTuple_Pack(2, errstr, tmp);
if (!value) {
goto error;
result = -1;
goto exit;
}

PyErr_SetObject(errtype, value);
Py_DECREF(value);
return 0;
error:

exit:
Py_XDECREF(errstr);
Py_XDECREF(error_line);
return -1;
Py_XDECREF(tmp);
Py_XDECREF(value);
return result;
}

static PyObject *
Expand Down
0