chalk-diagrams / chalk

A declarative drawing API in Python
MIT License
282 stars 13 forks source link

Rewrite and simplification of Chalk core #132

Closed srush closed 6 months ago

srush commented 6 months ago

I was reading about some of the more recent updates to the Python type system and thought I would try a new version of the chalk core that fixed things that bothered me. This is a rather big PR, but most of it is pretty simple.

Changes:

Issues:

Why?

https://chalk-diagrams.github.io/viz/

image

danoneata commented 6 months ago

Thank you, Sasha! I'll take a closer look at the PR in the next couple of days (on Thursday probably). The penzai visualization looks sleek! I think it can be really useful for debugging!

danoneata commented 6 months ago
  • Make Visitor define an explicit generic argument for its down / up elements.

Nice; I like that we now have the input type explicitly specified for the visit methods!

Default behavior is that the down element is a monoid and define default behavoirs for compose, empty, etc.

I was curious: for the ToSVG visitor, the return type is svgwrite.base.BaseElement; how does that the type system know that this is a Monoid?

By the way, how do you type check code? Are you still using mypy? Which version and which options?

srush commented 6 months ago
danoneata commented 6 months ago

Thanks for the pull request and merge!

I am using mypy 1.10, should we switch to pyright?

Hmm... I don't have a strong opinion towards one or the other. But I see that pyright reports a few errors on our codebase (although I expect these to be fixable).

srush commented 6 months ago

K, I think I'll fix these, bump the required version to 3.10+, update the docs, and then up the version number. Excited to check out the animation lib as well.