Skip to content

Commit

Permalink
[spec/ysh-json] Add failing test case
Browse files Browse the repository at this point in the history
We're doing reference counting, not cycle detection!  In both JSON and
ASDL.

[ASDL] Fix type annotations in generated Python.
  • Loading branch information
Andy C committed Feb 3, 2024
1 parent c4f222e commit 05a85ea
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
6 changes: 3 additions & 3 deletions asdl/gen_python.py
Expand Up @@ -385,7 +385,7 @@ def _GenClass(self,
#

self.Emit(' def PrettyTree(self, trav=None):')
self.Emit(' # type: (TraversalState) -> hnode_t')
self.Emit(' # type: (Optional[TraversalState]) -> hnode_t')
self.Emit(' trav = trav or TraversalState()')
self.Emit(' heap_id = id(self)')
self.Emit(' if heap_id in trav.seen:')
Expand All @@ -412,7 +412,7 @@ def _GenClass(self,
#

self.Emit(' def _AbbreviatedTree(self, trav=None):')
self.Emit(' # type: (TraversalState) -> hnode_t')
self.Emit(' # type: (Optional[TraversalState]) -> hnode_t')
self.Emit(' trav = trav or TraversalState()')
self.Emit(' heap_id = id(self)')
self.Emit(' if heap_id in trav.seen:')
Expand All @@ -431,7 +431,7 @@ def _GenClass(self,
self.Emit('')

self.Emit(' def AbbreviatedTree(self, trav=None):')
self.Emit(' # type: (TraversalState) -> hnode_t')
self.Emit(' # type: (Optional[TraversalState]) -> hnode_t')
abbrev_name = '_%s' % class_name
if abbrev_name in self.abbrev_mod_entries:
self.Emit(' p = %s(self)' % abbrev_name)
Expand Down
7 changes: 7 additions & 0 deletions doc/pretty-printing.md
Expand Up @@ -114,7 +114,14 @@ Identical to the dynamically typed case above.
## TODO

- Fix ADSL cycle bug
- Fix it in C++

- distinguish ... vs ---

- Somehow do ASDL ref counts, because the thing is long
- to fix bin/osh -n


- Write separate parser for TYG8
- no commas, no JSON8, just () and []
- (unquotedyaks unquotedjs:value) and [value value]
Expand Down
2 changes: 1 addition & 1 deletion spec/ysh-builtin-meta.test.sh
@@ -1,4 +1,4 @@
## oils_failures_allowed: 2
## oils_failures_allowed: 1

#### pp asdl

Expand Down
16 changes: 15 additions & 1 deletion spec/ysh-json.test.sh
@@ -1,4 +1,4 @@
## oils_failures_allowed: 2
## oils_failures_allowed: 3
## tags: dev-minimal

#### usage errors
Expand Down Expand Up @@ -237,6 +237,20 @@ echo 'should have failed'
1:{ ...
## END

#### json write of List/Dict referenced twice (bug fix)

var mylist = [1,2,3]
var mydict = {foo: "bar"}

var top = {k: mylist, k2: mylist, k3: mydict, k4: mydict}

# BUG!
json write (top)

## STDOUT:
## END


#### json read doesn't accept u'' or b'' strings

json read <<EOF
Expand Down

0 comments on commit 05a85ea

Please sign in to comment.