Skip to content

Commit

Permalink
Python tree-sitter to CAST porting: Classes (#850)
Browse files Browse the repository at this point in the history
This PR introduces support for generating CAST for Python Classes. In
CAST the translation for these is RecordDef. This is part of the ongoing
effort of porting over the Python to CAST generation to use tree-sitter
instead of the Python AST.

### Summary of Changes
- Adds support in python/ts2cast.py for generating RecordDef CAST nodes,
which represent Python classes.
- Adds test script test_record_cast.py for maintaining consistency with
basic examples.
- Adds a handler of CAST Name nodes for when they're being used in
Operators or returns (get_operand_node). This is to make sure the
correct CAST node is being used in these at all times.
- Very minor code cleanup.

Resolves #805

---------

Co-authored-by: Vincent Raymond <vincent@lum.ai> 1e379f3
  • Loading branch information
github-actions[bot] committed Mar 13, 2024
1 parent 6c73026 commit ca046e6
Show file tree
Hide file tree
Showing 1,756 changed files with 226,623 additions and 224,703 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ <h3>Instance variables</h3>
<h3>Methods</h3>
<dl>
<dt id="skema.img2mml.models.decoders.xfmer_decoder.Transformer_Decoder.create_pad_mask"><code class="name flex">
<span>def <span class="ident">create_pad_mask</span></span>(<span>self, matrix: <built-in method tensor of type object at 0x7f52c1f5b500>, pad_token: int) ‑> <built-in method tensor of type object at 0x7f52c1f5b500></span>
<span>def <span class="ident">create_pad_mask</span></span>(<span>self, matrix: <built-in method tensor of type object at 0x7f26c4b5b500>, pad_token: int) ‑> <built-in method tensor of type object at 0x7f26c4b5b500></span>
</code></dt>
<dd>
<div class="desc"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ <h3>Class variables</h3>
<h3>Methods</h3>
<dl>
<dt id="skema.img2mml.models.encoding.positional_encoding_for_xfmer.PositionalEncoding.forward"><code class="name flex">
<span>def <span class="ident">forward</span></span>(<span>self, x: <built-in method tensor of type object at 0x7f52c1f5b500>) ‑> <built-in method tensor of type object at 0x7f52c1f5b500></span>
<span>def <span class="ident">forward</span></span>(<span>self, x: <built-in method tensor of type object at 0x7f26c4b5b500>) ‑> <built-in method tensor of type object at 0x7f26c4b5b500></span>
</code></dt>
<dd>
<div class="desc"><p>Defines the computation performed at every call.</p>
Expand Down
205 changes: 193 additions & 12 deletions api/python/skema/program_analysis/CAST/python/ts2cast.html

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions api/python/skema/program_analysis/tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ <h2 class="section-title" id="header-submodules">Sub-modules</h2>
<dd>
<div class="desc"></div>
</dd>
<dt><code class="name"><a title="skema.program_analysis.tests.test_record_cast" href="test_record_cast.html">skema.program_analysis.tests.test_record_cast</a></code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt><code class="name"><a title="skema.program_analysis.tests.test_recursion" href="test_recursion.html">skema.program_analysis.tests.test_recursion</a></code></dt>
<dd>
<div class="desc"></div>
Expand Down Expand Up @@ -180,6 +184,7 @@ <h1>Index</h1>
<li><code><a title="skema.program_analysis.tests.test_model_coverage" href="test_model_coverage.html">skema.program_analysis.tests.test_model_coverage</a></code></li>
<li><code><a title="skema.program_analysis.tests.test_operation_cast" href="test_operation_cast.html">skema.program_analysis.tests.test_operation_cast</a></code></li>
<li><code><a title="skema.program_analysis.tests.test_primitive" href="test_primitive.html">skema.program_analysis.tests.test_primitive</a></code></li>
<li><code><a title="skema.program_analysis.tests.test_record_cast" href="test_record_cast.html">skema.program_analysis.tests.test_record_cast</a></code></li>
<li><code><a title="skema.program_analysis.tests.test_recursion" href="test_recursion.html">skema.program_analysis.tests.test_recursion</a></code></li>
<li><code><a title="skema.program_analysis.tests.test_while_cast" href="test_while_cast.html">skema.program_analysis.tests.test_while_cast</a></code></li>
<li><code><a title="skema.program_analysis.tests.test_wiring_diagnosis" href="test_wiring_diagnosis.html">skema.program_analysis.tests.test_wiring_diagnosis</a></code></li>
Expand Down
12 changes: 6 additions & 6 deletions api/python/skema/program_analysis/tests/test_function_cast.html
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ <h1 class="title">Module <code>skema.program_analysis.tests.test_function_cast</

func_def_body = func_def_node.body[2]
assert isinstance(func_def_body, ModelReturn)
assert isinstance(func_def_body.value, Var)
assert isinstance(func_def_body.value, Name)

assert func_def_body.value.val.name == &#34;z&#34;
assert func_def_body.value.val.id == 4
assert func_def_body.value.name == &#34;z&#34;
assert func_def_body.value.id == 4

#######################################################
func_asg_node = fun_cast.nodes[0].body[1]
Expand Down Expand Up @@ -669,10 +669,10 @@ <h2 class="section-title" id="header-functions">Functions</h2>

func_def_body = func_def_node.body[2]
assert isinstance(func_def_body, ModelReturn)
assert isinstance(func_def_body.value, Var)
assert isinstance(func_def_body.value, Name)

assert func_def_body.value.val.name == &#34;z&#34;
assert func_def_body.value.val.id == 4
assert func_def_body.value.name == &#34;z&#34;
assert func_def_body.value.id == 4

#######################################################
func_asg_node = fun_cast.nodes[0].body[1]
Expand Down
1,090 changes: 1,090 additions & 0 deletions api/python/skema/program_analysis/tests/test_record_cast.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions api/rust/actix_codec/struct.LinesCodec.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/rust/actix_http/body/trait.MessageBody.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,4 @@ <h5 id="errors"><a href="#errors">Errors</a></h5>
S: <a class="trait" href="../../futures_core/stream/trait.Stream.html" title="trait futures_core::stream::Stream">Stream</a>&lt;Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../bytes/bytes/struct.Bytes.html" title="struct bytes::bytes::Bytes">Bytes</a>, E&gt;&gt;,
E: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a>&lt;dyn <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/error/trait.Error.html" title="trait core::error::Error">StdError</a>&gt;&gt; + 'static,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.Error-19" class="associatedtype trait-impl"><a href="#associatedtype.Error-19" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Error" class="associatedtype">Error</a> = E</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-MessageBody-for-SizedStream%3CS%3E" class="impl"><a class="src rightside" href="../../src/actix_http/body/sized_stream.rs.html#38-70">source</a><a href="#impl-MessageBody-for-SizedStream%3CS%3E" class="anchor">§</a><h3 class="code-header">impl&lt;S, E&gt; <a class="trait" href="trait.MessageBody.html" title="trait actix_http::body::MessageBody">MessageBody</a> for <a class="struct" href="struct.SizedStream.html" title="struct actix_http::body::SizedStream">SizedStream</a>&lt;S&gt;<div class="where">where
S: <a class="trait" href="../../futures_core/stream/trait.Stream.html" title="trait futures_core::stream::Stream">Stream</a>&lt;Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../bytes/bytes/struct.Bytes.html" title="struct bytes::bytes::Bytes">Bytes</a>, E&gt;&gt;,
E: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a>&lt;dyn <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/error/trait.Error.html" title="trait core::error::Error">StdError</a>&gt;&gt; + 'static,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.Error-20" class="associatedtype trait-impl"><a href="#associatedtype.Error-20" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Error" class="associatedtype">Error</a> = E</h4></section></div></details></div><script src="../../trait.impl/actix_http/body/message_body/trait.MessageBody.js" data-ignore-extern-crates="alloc,core,bytestring,std,bytes" async></script></section></div></main></body></html>
E: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a>&lt;dyn <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/error/trait.Error.html" title="trait core::error::Error">StdError</a>&gt;&gt; + 'static,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.Error-20" class="associatedtype trait-impl"><a href="#associatedtype.Error-20" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Error" class="associatedtype">Error</a> = E</h4></section></div></details></div><script src="../../trait.impl/actix_http/body/message_body/trait.MessageBody.js" data-ignore-extern-crates="alloc,core,std,bytes,bytestring" async></script></section></div></main></body></html>
2 changes: 1 addition & 1 deletion api/rust/actix_http/enum.Payload.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/rust/actix_http/error/enum.ContentTypeError.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/rust/actix_http/error/enum.DispatchError.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/rust/actix_http/error/enum.ParseError.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/rust/actix_http/error/enum.PayloadError.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/rust/actix_http/error/struct.Error.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/rust/actix_http/error/struct.HttpError.html

Large diffs are not rendered by default.

Loading

0 comments on commit ca046e6

Please sign in to comment.