Comments (1)
In case there isn't a way to do this currently, how about something like a bang operator.
template toBangArg(inNode: NimNode, plainArgs: NimNode, kwArgs: NimNode) =
var node: NimNode
if inNode.kind == nnkPar:
node = inNode[0]
else:
node = inNode
if node.kind == nnkHiddenStdConv and node[0].kind == nnkEmpty:
discard
elif node.kind == nnkExprEqExpr or node.kind == nnkAsgn or node.kind == nnkExprColonExpr:
kwArgs.add(newTree(nnkPar,
newCall("cstring", newLit($node[0])),
newCall("toPyObjectArgument", node[1])))
else:
plainArgs.add(newCall("toPyObjectArgument", node))
macro `!`*(o: PyObject, args: varargs[untyped]): PyObject =
expectKind(o, nnkSym)
let plainArgs = newTree(nnkBracket)
let kwArgs = newTree(nnkBracket)
expectKind(args, nnkArgList)
expectLen(args, 1)
if args[0].kind == nnkTupleConstr:
for arg in args[0]:
toBangArg(arg, plainArgs, kwArgs)
else:
toBangArg(args[0], plainArgs, kwArgs)
result = newCall(bindSym"newPyObjectConsumingRef",
newCall(bindSym"callObjectAux", newDotExpr(o, newIdentNode("rawPyObj")), plainArgs, kwArgs))
This would allow the object to be called like this discard tqdm!(nil, desc: "column", total: 5)
I wanted to make it work like this discard tqdm!(nil, desc="column", total=5)
but it seems that nim has issue parsing macros with multiple kwargs if no arg is passed, e.g., discard tqdm!(desc="column", total=5)
doesn't compile. However, the colon does align nim's constructor style.
If you think this is completely stupid, no problem, I can always work around this on my own. If you think this is something worth pursuing, I can make a PR.
from nimpy.
Related Issues (20)
- Could not find platform dependent libraries <exec_prefix> HOT 3
- Codon
- have some trouble printing a module's version HOT 1
- keeping long lived objects alive from python HOT 2
- Import local py file HOT 2
- Nim 2.0 compatibility HOT 2
- [Bug] Using nim procedures as Python decorators is not working HOT 2
- How to unpack PPyObject (dict) to kwargs in Nim? HOT 1
- It is possible to call async function? HOT 1
- How to use python decorators HOT 1
- Error: type mismatch: nimpy.nim(223, 37) HOT 1
- undefined symbol: _PyModule_Add [Exception] HOT 3
- Nim Version 2.0 breaks (Mac) HOT 4
- Issue importing in windows HOT 8
- Examples do not compile - `type mismatch` HOT 1
- Python Command Line Arguments Disappearing HOT 1
- How to pass Windows data types like HWND & HBRUSH
- Nimpy cannot import modules with default python 3.12 install on Windows 11
- __dict__ or __slots__ implementation
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 nimpy.