Search code examples
hy

Weird HyLang dot notation behavior


Why does the following work:

(def session (sessionmaker))
(.configure session :bind engine)

...but (def session (.configure (sessionmaker) :bind engine)) causes my Hy application to throw a NoneType TypeError?


Solution

  • So (sessionmaker) makes a "session" object? Does the (.configure (sessionmaker) :bind engine) method call return that session object? Or is it just for a side effect? I suspect it's the latter and just returns None. You might be looking for the doto form, which lets you configure an object, but then returns it at the end. So the code would be

    (def session (doto (sessionmaker) (.configure :bind engine)))
    

    If you're familiar with Python, the $ hy --spy option in the REPL is very useful for understanding how Hy gets compiled.