| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -77,14 +77,6 @@ typedef struct _PyCfgBuilder cfg_builder; | |||
| 77 | 77 | #define LOCATION(LNO, END_LNO, COL, END_COL) \ | |
| 78 | 78 | ((const _Py_SourceLocation){(LNO), (END_LNO), (COL), (END_COL)}) | |
| 79 | 79 | ||
| 80 | - /* Return true if loc1 starts after loc2 ends. */ | ||
| 81 | - static inline bool | ||
| 82 | - location_is_after(location loc1, location loc2) { | ||
| 83 | - return (loc1.lineno > loc2.end_lineno) || | ||
| 84 | - ((loc1.lineno == loc2.end_lineno) && | ||
| 85 | - (loc1.col_offset > loc2.end_col_offset)); | ||
| 86 | - } | ||
| 87 | - | ||
| 88 | 80 | #define LOC(x) SRC_LOCATION_FROM_AST(x) | |
| 89 | 81 | ||
| 90 | 82 | typedef _PyJumpTargetLabel jump_target_label; | |
@@ -3847,14 +3839,6 @@ compiler_from_import(struct compiler *c, stmt_ty s) | |||
| 3847 | 3839 | PyTuple_SET_ITEM(names, i, Py_NewRef(alias->name)); | |
| 3848 | 3840 | } | |
| 3849 | 3841 | ||
| 3850 | - if (location_is_after(LOC(s), c->c_future.ff_location) && | ||
| 3851 | - s->v.ImportFrom.module && s->v.ImportFrom.level == 0 && | ||
| 3852 | - _PyUnicode_EqualToASCIIString(s->v.ImportFrom.module, "__future__")) | ||
| 3853 | - { | ||
| 3854 | - Py_DECREF(names); | ||
| 3855 | - return compiler_error(c, LOC(s), "from __future__ imports must occur " | ||
| 3856 | - "at the beginning of the file"); | ||
| 3857 | - } | ||
| 3858 | 3842 | ADDOP_LOAD_CONST_NEW(c, LOC(s), names); | |
| 3859 | 3843 | ||
| 3860 | 3844 | if (s->v.ImportFrom.module) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1660,6 +1660,27 @@ has_kwonlydefaults(asdl_arg_seq *kwonlyargs, asdl_expr_seq *kw_defaults) | |||
| 1660 | 1660 | return 0; | |
| 1661 | 1661 | } | |
| 1662 | 1662 | ||
| 1663 | + static int | ||
| 1664 | + check_import_from(struct symtable *st, stmt_ty s) | ||
| 1665 | + { | ||
| 1666 | + assert(s->kind == ImportFrom_kind); | ||
| 1667 | + _Py_SourceLocation fut = st->st_future->ff_location; | ||
| 1668 | + if (s->v.ImportFrom.module && s->v.ImportFrom.level == 0 && | ||
| 1669 | + _PyUnicode_EqualToASCIIString(s->v.ImportFrom.module, "__future__") && | ||
| 1670 | + ((s->lineno > fut.lineno) || | ||
| 1671 | + ((s->lineno == fut.end_lineno) && (s->col_offset > fut.end_col_offset)))) | ||
| 1672 | + { | ||
| 1673 | + PyErr_SetString(PyExc_SyntaxError, | ||
| 1674 | + "from __future__ imports must occur " | ||
| 1675 | + "at the beginning of the file"); | ||
| 1676 | + PyErr_RangedSyntaxLocationObject(st->st_filename, | ||
| 1677 | + s->lineno, s->col_offset + 1, | ||
| 1678 | + s->end_lineno, s->end_col_offset + 1); | ||
| 1679 | + return 0; | ||
| 1680 | + } | ||
| 1681 | + return 1; | ||
| 1682 | + } | ||
| 1683 | + | ||
| 1663 | 1684 | static int | |
| 1664 | 1685 | symtable_visit_stmt(struct symtable *st, stmt_ty s) | |
| 1665 | 1686 | { | |
@@ -1914,6 +1935,9 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s) | |||
| 1914 | 1935 | break; | |
| 1915 | 1936 | case ImportFrom_kind: | |
| 1916 | 1937 | VISIT_SEQ(st, alias, s->v.ImportFrom.names); | |
| 1938 | + if (!check_import_from(st, s)) { | ||
| 1939 | + VISIT_QUIT(st, 0); | ||
| 1940 | + } | ||
| 1917 | 1941 | break; | |
| 1918 | 1942 | case Global_kind: { | |
| 1919 | 1943 | Py_ssize_t i; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments