Comments (4)
Thanks for the bug report! We should be able to fix this. Will write back with updates.
from marimo.
@mwchase, I have a fix, but I just want to make sure this is a bug, instead of intended behavior. Can you help me think through it?
It's possible to use type annotations at runtime. Popular libraries such as Pydantic do this. In such cases, could it be that marimo should indeed treat type annotations as names, not strings? In your specific case, you could replace the type annotations with actual strings, in which case the Python AST will contain Constant
nodes for "A"
and "B"
, not Name
nodes.
For example, consider this toy notebook. In this case it could be argued that the cell defining B
has a legitimate dependency on the cell defining A
.
import marimo
__generated_with = "0.1.56"
app = marimo.App()
@app.cell
def __():
class A:
"""hello world"""
return A,
@app.cell
def __(A, typing):
class B:
def use_type_annotations(self, a: A) -> None:
print(typing.get_type_hints(B.use_type_annotations)["a"].__doc__)
return B,
@app.cell
def __(B):
b = B()
return b,
@app.cell
def __(A, b):
b.use_type_annotations(A())
return
@app.cell
def __():
import typing
return typing,
if __name__ == "__main__":
app.run()
Given this complication I am leaning toward "intended behavior", but I am not certain. Let me know what you think?
from marimo.
Huh. I took that code, started messing with it, and got very confused. Taking a closer look, here's what happens if I change the example you gave to use "A"
in the annotation:
Cell 1 no longer depends on Cell 0, but Cell 3 still depends on Cell 0, so the code in Cell 1 can properly resolve the types, when Cell 3 calls it.
If I break the dependency from Cell 3 to Cell 0, I get undesirable behavior in the form of changes not propagating through the dependency graph.
From a quick glance at Pydantic, I can see that it's not unreasonable to end up in a scenario analogous to "there is no dependency between Cell 3 and Cell 0".
Unless someone comes up with a really compelling reason, probably the behavior should stay as-is (for maximum expressiveness within Python), but this probably merits some documentation.
In terms of, "on the one hand, using strings can break cycles, but on the other hand, using strings can break dependencies".
from marimo.
@mwchase , thanks for taking a look and for the thoughtful experiment.
Unless someone comes up with a really compelling reason, probably the behavior should stay as-is (for maximum expressiveness within Python), but this probably merits some documentation.
Great, we're on the same page.
In terms of, "on the one hand, using strings can break cycles, but on the other hand, using strings can break dependencies".
I like this suggestion — it's a good way to think about it. If dependencies are really needed, then best to not use strings, and declare the two dependent types/classes/functions in the same cell when possible.
I will add documentation to this effect somewhere on docs.marimo.io
. Perhaps in the FAQ, and/or the reactivity guide. Once that's done I'll close this issue.
Thanks again for the thoughtful and fun discussion!
from marimo.
Related Issues (20)
- Possibility of placing "Spinner" element anywhere on UI, similar to other UI components (Buttons, forms etc.) HOT 1
- plotly plot range_x not reactive except for app mode HOT 1
- Output in async mode not as expected HOT 2
- enabling marimo CSV transformer breaks altair plot in 4.7 HOT 1
- vstack and hstack not working as intended HOT 4
- Support serving static files through symlinks HOT 9
- Blocking tasks (sync or async) leads to ui frozen HOT 2
- Native Cached Results HOT 1
- mo.ui.table crashes browser when used with very large dataframe HOT 4
- ui.table crashes on table with duplicate column names
- Add typo check to make py-test 😢 HOT 2
- possibility to update state via thread and have dependencies executed HOT 7
- ui.dataframe transforms incorrectly assume string column names HOT 1
- Unable to run pyodide HOT 3
- VSCode debugger support: 'debug cell' HOT 11
- On resume session (browser refresh), execution time is lost HOT 1
- SyntaxWarning being spammed in console log HOT 6
- Admonitions? HOT 3
- Home doesn't detect new files HOT 2
- Holoviews with Bokeh themes doesn't display correctly
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from marimo.