Skip to content
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

update update vendored packages #617

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/poetry/core/_vendor/lark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .utils import logger
from .visitors import Discard, Transformer, Transformer_NonRecursive, Visitor, v_args

__version__: str = "1.1.5"
__version__: str = "1.1.7"

__all__ = (
"GrammarError",
Expand Down
5 changes: 4 additions & 1 deletion src/poetry/core/_vendor/lark/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ class LexerConf(Serialize):
skip_validation: bool
use_bytes: bool
lexer_type: Optional[_LexerArgType]
strict: bool

def __init__(self, terminals: Collection[TerminalDef], re_module: ModuleType, ignore: Collection[str]=(), postlex: 'Optional[PostLex]'=None, callbacks: Optional[Dict[str, _Callback]]=None, g_regex_flags: int=0, skip_validation: bool=False, use_bytes: bool=False):
def __init__(self, terminals: Collection[TerminalDef], re_module: ModuleType, ignore: Collection[str]=(), postlex: 'Optional[PostLex]'=None,
callbacks: Optional[Dict[str, _Callback]]=None, g_regex_flags: int=0, skip_validation: bool=False, use_bytes: bool=False, strict: bool=False):
self.terminals = terminals
self.terminals_by_name = {t.name: t for t in self.terminals}
assert len(self.terminals) == len(self.terminals_by_name)
Expand All @@ -50,6 +52,7 @@ def __init__(self, terminals: Collection[TerminalDef], re_module: ModuleType, ig
self.re_module = re_module
self.skip_validation = skip_validation
self.use_bytes = use_bytes
self.strict = strict
self.lexer_type = None

def _deserialize(self):
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/core/_vendor/lark/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class UnexpectedToken(ParseError, UnexpectedInput):
expected: The set of expected tokens
considered_rules: Which rules were considered, to deduce the expected tokens
state: A value representing the parser state. Do not rely on its value or type.
interactive_parser: An instance of ``InteractiveParser``, that is initialized to the point of failture,
interactive_parser: An instance of ``InteractiveParser``, that is initialized to the point of failure,
and can be used for debugging and error handling.

Note: These parameters are available as attributes of the instance.
Expand Down
5 changes: 4 additions & 1 deletion src/poetry/core/_vendor/lark/grammars/lark.lark
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Lark grammar of Lark's syntax
# Note: Lark is not bootstrapped, its parser is implemented in load_grammar.py

start: (_item? _NL)* _item?

_item: rule
Expand Down Expand Up @@ -53,7 +56,7 @@ _NL: /(\r?\n)+\s*/
%import common.SIGNED_INT -> NUMBER
%import common.WS_INLINE

COMMENT: /\s*/ "//" /[^\n]/*
COMMENT: /\s*/ "//" /[^\n]/* | /\s*/ "#" /[^\n]/*

%ignore WS_INLINE
%ignore COMMENT
8 changes: 3 additions & 5 deletions src/poetry/core/_vendor/lark/grammars/python.lark
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ AWAIT: "await"
?atom: "(" yield_expr ")"
| "(" _tuple_inner? ")" -> tuple
| "(" comprehension{test_or_star_expr} ")" -> tuple_comprehension
| "[" _testlist_comp? "]" -> list
| "[" _exprlist? "]" -> list
| "[" comprehension{test_or_star_expr} "]" -> list_comprehension
| "{" _dict_exprlist? "}" -> dict
| "{" comprehension{key_value} "}" -> dict_comprehension
| "{" _set_exprlist "}" -> set
| "{" _exprlist "}" -> set
| "{" comprehension{test} "}" -> set_comprehension
| name -> var
| number
Expand All @@ -215,10 +215,8 @@ AWAIT: "await"

?string_concat: string+

_testlist_comp: test | _tuple_inner
_tuple_inner: test_or_star_expr (("," test_or_star_expr)+ [","] | ",")


?test_or_star_expr: test
| star_expr

Expand All @@ -234,7 +232,7 @@ _dict_exprlist: (key_value | "**" expr) ("," (key_value | "**" expr))* [","]

key_value: test ":" test

_set_exprlist: test_or_star_expr ("," test_or_star_expr)* [","]
_exprlist: test_or_star_expr ("," test_or_star_expr)* [","]

classdef: "class" name ["(" [arguments] ")"] ":" suite

Expand Down
27 changes: 17 additions & 10 deletions src/poetry/core/_vendor/lark/lark.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from .exceptions import ConfigurationError, assert_config, UnexpectedInput
from .utils import Serialize, SerializeMemoizer, FS, isascii, logger
from .load_grammar import load_grammar, FromPackageLoader, Grammar, verify_used_files, PackageResource, md5_digest
from .load_grammar import load_grammar, FromPackageLoader, Grammar, verify_used_files, PackageResource, sha256_digest
from .tree import Tree
from .common import LexerConf, ParserConf, _ParserArgType, _LexerArgType

Expand Down Expand Up @@ -54,6 +54,7 @@ class LarkOptions(Serialize):

start: List[str]
debug: bool
strict: bool
transformer: 'Optional[Transformer]'
propagate_positions: Union[bool, str]
maybe_placeholders: bool
Expand Down Expand Up @@ -81,10 +82,14 @@ class LarkOptions(Serialize):
debug
Display debug information and extra warnings. Use only when debugging (Default: ``False``)
When used with Earley, it generates a forest graph as "sppf.png", if 'dot' is installed.
strict
Throw an exception on any potential ambiguity, including shift/reduce conflicts, and regex collisions.
transformer
Applies the transformer to every parse tree (equivalent to applying it after the parse, but faster)
propagate_positions
Propagates (line, column, end_line, end_column) attributes into all tree branches.
Propagates positional attributes into the 'meta' attribute of all tree branches.
Sets attributes: (line, column, end_line, end_column, start_pos, end_pos,
container_line, container_column, container_end_line, container_end_column)
Accepts ``False``, ``True``, or a callable, which will filter which nodes to ignore when propagating.
maybe_placeholders
When ``True``, the ``[]`` operator returns ``None`` when not matched.
Expand Down Expand Up @@ -156,6 +161,7 @@ class LarkOptions(Serialize):
# - Potentially in `lark.tools.__init__`, if it makes sense, and it can easily be passed as a cmd argument
_defaults: Dict[str, Any] = {
'debug': False,
'strict': False,
'keep_all_tokens': False,
'tree_class': None,
'cache': False,
Expand Down Expand Up @@ -254,6 +260,7 @@ class Lark(Serialize):
grammar: 'Grammar'
options: LarkOptions
lexer: Lexer
parser: 'ParsingFrontend'
terminals: Collection[TerminalDef]

def __init__(self, grammar: 'Union[Grammar, str, IO[str]]', **options) -> None:
Expand Down Expand Up @@ -288,7 +295,7 @@ def __init__(self, grammar: 'Union[Grammar, str, IO[str]]', **options) -> None:
grammar = read()

cache_fn = None
cache_md5 = None
cache_sha256 = None
if isinstance(grammar, str):
self.source_grammar = grammar
if self.options.use_bytes:
Expand All @@ -303,7 +310,7 @@ def __init__(self, grammar: 'Union[Grammar, str, IO[str]]', **options) -> None:
options_str = ''.join(k+str(v) for k, v in options.items() if k not in unhashable)
from . import __version__
s = grammar + options_str + __version__ + str(sys.version_info[:2])
cache_md5 = md5_digest(s)
cache_sha256 = sha256_digest(s)

if isinstance(self.options.cache, str):
cache_fn = self.options.cache
Expand All @@ -319,7 +326,7 @@ def __init__(self, grammar: 'Union[Grammar, str, IO[str]]', **options) -> None:
# specific reason - we just want a username.
username = "unknown"

cache_fn = tempfile.gettempdir() + "/.lark_cache_%s_%s_%s_%s.tmp" % (username, cache_md5, *sys.version_info[:2])
cache_fn = tempfile.gettempdir() + "/.lark_cache_%s_%s_%s_%s.tmp" % (username, cache_sha256, *sys.version_info[:2])

old_options = self.options
try:
Expand All @@ -328,9 +335,9 @@ def __init__(self, grammar: 'Union[Grammar, str, IO[str]]', **options) -> None:
# Remove options that aren't relevant for loading from cache
for name in (set(options) - _LOAD_ALLOWED_OPTIONS):
del options[name]
file_md5 = f.readline().rstrip(b'\n')
file_sha256 = f.readline().rstrip(b'\n')
cached_used_files = pickle.load(f)
if file_md5 == cache_md5.encode('utf8') and verify_used_files(cached_used_files):
if file_sha256 == cache_sha256.encode('utf8') and verify_used_files(cached_used_files):
cached_parser_data = pickle.load(f)
self._load(cached_parser_data, **options)
return
Expand Down Expand Up @@ -424,7 +431,7 @@ def __init__(self, grammar: 'Union[Grammar, str, IO[str]]', **options) -> None:
# TODO Deprecate lexer_callbacks?
self.lexer_conf = LexerConf(
self.terminals, re_module, self.ignore_tokens, self.options.postlex,
self.options.lexer_callbacks, self.options.g_regex_flags, use_bytes=self.options.use_bytes
self.options.lexer_callbacks, self.options.g_regex_flags, use_bytes=self.options.use_bytes, strict=self.options.strict
)

if self.options.parser:
Expand All @@ -436,8 +443,8 @@ def __init__(self, grammar: 'Union[Grammar, str, IO[str]]', **options) -> None:
logger.debug('Saving grammar to cache: %s', cache_fn)
try:
with FS.open(cache_fn, 'wb') as f:
assert cache_md5 is not None
f.write(cache_md5.encode('utf8') + b'\n')
assert cache_sha256 is not None
f.write(cache_sha256.encode('utf8') + b'\n')
pickle.dump(used_files, f)
self.save(f, _LOAD_ALLOWED_OPTIONS)
except IOError as e:
Expand Down
Loading