mirror of
https://github.com/github/codeql.git
synced 2026-04-17 21:14:02 +02:00
Python: Add parser support for lazy imports
As defined in PEP-810. We implement this in much the same way as how we handle `async` annotations currently. The relevant nodes get an `is_lazy` field that defaults to being false.
This commit is contained in:
@@ -845,17 +845,19 @@ class If(stmt):
|
||||
|
||||
|
||||
class Import(stmt):
|
||||
__slots__ = "names",
|
||||
__slots__ = "is_lazy", "names",
|
||||
|
||||
def __init__(self, names):
|
||||
def __init__(self, names, is_lazy=False):
|
||||
self.names = names
|
||||
self.is_lazy = is_lazy
|
||||
|
||||
|
||||
class ImportFrom(stmt):
|
||||
__slots__ = "module",
|
||||
__slots__ = "is_lazy", "module",
|
||||
|
||||
def __init__(self, module):
|
||||
def __init__(self, module, is_lazy=False):
|
||||
self.module = module
|
||||
self.is_lazy = is_lazy
|
||||
|
||||
|
||||
class Nonlocal(stmt):
|
||||
|
||||
@@ -72,8 +72,8 @@ class AstDumper(object):
|
||||
# just not print it in that case.
|
||||
if field == "parenthesised" and value is None:
|
||||
continue
|
||||
# Likewise, the default value for `is_async` is `False`, so we don't need to print it.
|
||||
if field == "is_async" and value is False:
|
||||
# Likewise, the default value for `is_async` and `is_lazy` is `False`, so we don't need to print it.
|
||||
if field in ("is_async", "is_lazy") and value is False:
|
||||
continue
|
||||
output.write("{} {}:".format(indent,field))
|
||||
if isinstance(value, list):
|
||||
|
||||
@@ -291,7 +291,7 @@ def create_placeholder_args(cls):
|
||||
if cls in (ast.Raise, ast.Ellipsis):
|
||||
return {}
|
||||
fields = ast_fields[cls]
|
||||
args = {field: None for field in fields if field != "is_async"}
|
||||
args = {field: None for field in fields if field not in ("is_async", "is_lazy")}
|
||||
for field in list_fields.get(cls, ()):
|
||||
args[field] = []
|
||||
if cls in (ast.GeneratorExp, ast.ListComp, ast.SetComp, ast.DictComp):
|
||||
|
||||
Reference in New Issue
Block a user