mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
merge 3.2
This commit is contained in:
commit
86f088e8e5
4 changed files with 55 additions and 4 deletions
|
@ -367,6 +367,20 @@ class AST_Tests(unittest.TestCase):
|
||||||
compile(m, "<test>", "exec")
|
compile(m, "<test>", "exec")
|
||||||
self.assertIn("but got <_ast.expr", str(cm.exception))
|
self.assertIn("but got <_ast.expr", str(cm.exception))
|
||||||
|
|
||||||
|
def test_invalid_identitifer(self):
|
||||||
|
m = ast.Module([ast.Expr(ast.Name(42, ast.Load()))])
|
||||||
|
ast.fix_missing_locations(m)
|
||||||
|
with self.assertRaises(TypeError) as cm:
|
||||||
|
compile(m, "<test>", "exec")
|
||||||
|
self.assertIn("identifier must be of type str", str(cm.exception))
|
||||||
|
|
||||||
|
def test_invalid_string(self):
|
||||||
|
m = ast.Module([ast.Expr(ast.Str(42))])
|
||||||
|
ast.fix_missing_locations(m)
|
||||||
|
with self.assertRaises(TypeError) as cm:
|
||||||
|
compile(m, "<test>", "exec")
|
||||||
|
self.assertIn("string must be of type str", str(cm.exception))
|
||||||
|
|
||||||
|
|
||||||
class ASTHelpers_Test(unittest.TestCase):
|
class ASTHelpers_Test(unittest.TestCase):
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,9 @@ What's New in Python 3.3 Alpha 1?
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Verify the types of AST strings and identifiers provided by the user before
|
||||||
|
compiling them.
|
||||||
|
|
||||||
- Issue #12579: str.format_map() now raises a ValueError if used on a
|
- Issue #12579: str.format_map() now raises a ValueError if used on a
|
||||||
format string that contains positional fields. Initial patch by
|
format string that contains positional fields. Initial patch by
|
||||||
Julian Berman.
|
Julian Berman.
|
||||||
|
|
|
@ -795,8 +795,25 @@ static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define obj2ast_identifier obj2ast_object
|
static int obj2ast_stringlike(PyObject* obj, PyObject** out, PyArena* arena,
|
||||||
#define obj2ast_string obj2ast_object
|
const char *name)
|
||||||
|
{
|
||||||
|
if (!PyUnicode_CheckExact(name)) {
|
||||||
|
PyErr_Format(PyExc_TypeError, "AST %s must be of type str", name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return obj2ast_object(obj, out, arena);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
|
||||||
|
{
|
||||||
|
return obj2ast_stringlike(obj, out, arena, "identifier");
|
||||||
|
}
|
||||||
|
|
||||||
|
static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
|
||||||
|
{
|
||||||
|
return obj2ast_stringlike(obj, out, arena, "string");
|
||||||
|
}
|
||||||
|
|
||||||
static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
|
static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
|
||||||
{
|
{
|
||||||
|
|
|
@ -592,8 +592,25 @@ static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define obj2ast_identifier obj2ast_object
|
static int obj2ast_stringlike(PyObject* obj, PyObject** out, PyArena* arena,
|
||||||
#define obj2ast_string obj2ast_object
|
const char *name)
|
||||||
|
{
|
||||||
|
if (!PyUnicode_CheckExact(name)) {
|
||||||
|
PyErr_Format(PyExc_TypeError, "AST %s must be of type str", name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return obj2ast_object(obj, out, arena);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
|
||||||
|
{
|
||||||
|
return obj2ast_stringlike(obj, out, arena, "identifier");
|
||||||
|
}
|
||||||
|
|
||||||
|
static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
|
||||||
|
{
|
||||||
|
return obj2ast_stringlike(obj, out, arena, "string");
|
||||||
|
}
|
||||||
|
|
||||||
static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
|
static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue