mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-06-27 17:08:32 +00:00
[devalue] add code comments
Authored by: bashonly
This commit is contained in:
parent
39cb150d76
commit
ac834cb366
@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
|
|
||||||
def parse_iter(parsed: typing.Any, /, *, revivers: dict[str, collections.abc.Callable[[list], typing.Any]] | None = None):
|
def parse_iter(parsed: typing.Any, /, *, revivers: dict[str, collections.abc.Callable[[list], typing.Any]] | None = None):
|
||||||
|
# based on https://github.com/Rich-Harris/devalue/blob/f3fd2aa93d79f21746555671f955a897335edb1b/src/parse.js
|
||||||
resolved = {
|
resolved = {
|
||||||
-1: None,
|
-1: None,
|
||||||
-2: None,
|
-2: None,
|
||||||
@ -69,6 +70,7 @@ def parse_iter(parsed: typing.Any, /, *, revivers: dict[str, collections.abc.Cal
|
|||||||
target[index] = resolved[source]
|
target[index] = resolved[source]
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# guard against Python negative indexing
|
||||||
if source < 0:
|
if source < 0:
|
||||||
yield IndexError(f'invalid index: {source!r}')
|
yield IndexError(f'invalid index: {source!r}')
|
||||||
continue
|
continue
|
||||||
@ -79,6 +81,7 @@ def parse_iter(parsed: typing.Any, /, *, revivers: dict[str, collections.abc.Cal
|
|||||||
# TODO: implement zips `strict=True`
|
# TODO: implement zips `strict=True`
|
||||||
if reviver := revivers.get(value[0]):
|
if reviver := revivers.get(value[0]):
|
||||||
if value[1] == source:
|
if value[1] == source:
|
||||||
|
# XXX: avoid infinite loop
|
||||||
yield IndexError(f'{value[0]!r} cannot point to itself (index: {source})')
|
yield IndexError(f'{value[0]!r} cannot point to itself (index: {source})')
|
||||||
continue
|
continue
|
||||||
# inverse order: resolve index, revive value
|
# inverse order: resolve index, revive value
|
||||||
|
Loading…
Reference in New Issue
Block a user