diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-07-12 10:27:19 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-07-12 10:39:26 +0300 |
commit | c01ce9fa40ae2926a9dfce1c2d91f1f7ec1ef7ce (patch) | |
tree | 0cf6869d1af7f23c2497d6b8c744d537d4637b16 | |
parent | dbabef8aa606161028360a986813fefe5729be40 (diff) | |
download | ydb-c01ce9fa40ae2926a9dfce1c2d91f1f7ec1ef7ce.tar.gz |
Intermediate changes
-rw-r--r-- | contrib/python/gast/.dist-info/METADATA | 2 | ||||
-rw-r--r-- | contrib/python/gast/gast/__init__.py | 2 | ||||
-rw-r--r-- | contrib/python/gast/gast/gast.py | 92 | ||||
-rw-r--r-- | contrib/python/gast/gast/version.py | 2 | ||||
-rw-r--r-- | contrib/python/gast/ya.make | 2 | ||||
-rwxr-xr-x | ya | 5 |
6 files changed, 100 insertions, 5 deletions
diff --git a/contrib/python/gast/.dist-info/METADATA b/contrib/python/gast/.dist-info/METADATA index 8dfcb9334d..6dfe2acf1e 100644 --- a/contrib/python/gast/.dist-info/METADATA +++ b/contrib/python/gast/.dist-info/METADATA @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: gast -Version: 0.5.5 +Version: 0.6.0 Summary: Python AST that abstracts the underlying Python version Home-page: https://github.com/serge-sans-paille/gast/ Author: serge-sans-paille diff --git a/contrib/python/gast/gast/__init__.py b/contrib/python/gast/gast/__init__.py index 00c6f2cb55..8de66c693f 100644 --- a/contrib/python/gast/gast/__init__.py +++ b/contrib/python/gast/gast/__init__.py @@ -1,3 +1,3 @@ from .gast import * from .version import __version__ -from ast import NodeVisitor, NodeTransformer, iter_fields, dump +from ast import NodeVisitor, NodeTransformer, iter_fields diff --git a/contrib/python/gast/gast/gast.py b/contrib/python/gast/gast/gast.py index 6d558694e4..3081e535ce 100644 --- a/contrib/python/gast/gast/gast.py +++ b/contrib/python/gast/gast/gast.py @@ -469,3 +469,95 @@ def increment_lineno(node, n=1): if 'end_lineno' in child._attributes: child.end_lineno = (getattr(child, 'end_lineno', 0) or 0) + n return node + +if _sys.version_info.major == 3 and _sys.version_info.minor >= 13: + dump = _ast.dump +else: + # Code import from Lib/ast.py + # + # minor changes: getattr(x, y, ...) is None => getattr(x, y, 42) is None + # + def dump( + node, annotate_fields=True, include_attributes=False, + # *, # removed for compatibility with python2 :-/ + indent=None, show_empty=False, + ): + """ + Return a formatted dump of the tree in node. This is mainly useful for + debugging purposes. If annotate_fields is true (by default), + the returned string will show the names and the values for fields. + If annotate_fields is false, the result string will be more compact by + omitting unambiguous field names. Attributes such as line + numbers and column offsets are not dumped by default. If this is wanted, + include_attributes can be set to true. If indent is a non-negative + integer or string, then the tree will be pretty-printed with that indent + level. None (the default) selects the single line representation. + If show_empty is False, then empty lists and fields that are None + will be omitted from the output for better readability. + """ + def _format(node, level=0): + if indent is not None: + level += 1 + prefix = '\n' + indent * level + sep = ',\n' + indent * level + else: + prefix = '' + sep = ', ' + if isinstance(node, AST): + cls = type(node) + args = [] + args_buffer = [] + allsimple = True + keywords = annotate_fields + for name in node._fields: + try: + value = getattr(node, name) + except AttributeError: + keywords = True + continue + if value is None and getattr(cls, name, 42) is None: + keywords = True + continue + if ( + not show_empty + and (value is None or value == []) + # Special cases: + # `Constant(value=None)` and `MatchSingleton(value=None)` + and not isinstance(node, (Constant, MatchSingleton)) + ): + args_buffer.append(repr(value)) + continue + elif not keywords: + args.extend(args_buffer) + args_buffer = [] + value, simple = _format(value, level) + allsimple = allsimple and simple + if keywords: + args.append('%s=%s' % (name, value)) + else: + args.append(value) + if include_attributes and node._attributes: + for name in node._attributes: + try: + value = getattr(node, name) + except AttributeError: + continue + if value is None and getattr(cls, name, 42) is None: + continue + value, simple = _format(value, level) + allsimple = allsimple and simple + args.append('%s=%s' % (name, value)) + if allsimple and len(args) <= 3: + return '%s(%s)' % (node.__class__.__name__, ', '.join(args)), not args + return '%s(%s%s)' % (node.__class__.__name__, prefix, sep.join(args)), False + elif isinstance(node, list): + if not node: + return '[]', True + return '[%s%s]' % (prefix, sep.join(_format(x, level)[0] for x in node)), False + return repr(node), True + + if not isinstance(node, AST): + raise TypeError('expected AST, got %r' % node.__class__.__name__) + if indent is not None and not isinstance(indent, str): + indent = ' ' * indent + return _format(node)[0] diff --git a/contrib/python/gast/gast/version.py b/contrib/python/gast/gast/version.py index 31d29d8215..ef7eb44d9a 100644 --- a/contrib/python/gast/gast/version.py +++ b/contrib/python/gast/gast/version.py @@ -1 +1 @@ -__version__ = '0.5.5' +__version__ = '0.6.0' diff --git a/contrib/python/gast/ya.make b/contrib/python/gast/ya.make index d7fb535361..1e86b28163 100644 --- a/contrib/python/gast/ya.make +++ b/contrib/python/gast/ya.make @@ -2,7 +2,7 @@ PY3_LIBRARY() -VERSION(0.5.5) +VERSION(0.6.0) LICENSE(BSD-3-Clause) @@ -232,7 +232,10 @@ def _extract(path, into): # mock it with noop to retain current user ownership. tar.chown = lambda *args, **kwargs: None - tar.extractall(path=into) + if sys.version_info >= (3, 12): + tar.extractall(path=into, filter='data') + else: + tar.extractall(path=into) tar.close() |