Closed erhlee-bird closed 6 years ago
I am surprised b.__enter__
doesn't work, maybe that would make sense to be supported by nim's quotes
So patching the lexer to allow underscored identifiers within accent quotes is pretty straight forward. See: https://github.com/Vindaar/Nim/commit/d047887b8844851d748e30ff7755243f555ac543
Makes your example work fine, if as @alehander42 suggested, __enter__
is put into backticks.
If promoting good Python interoperability is a goal of Nim, this would be nice to have I guess. I can see it opening a can of worms though, although all tests seem to pass on my machine. I'm pretty skeptical this would actually get merged though. :)
I'm pretty skeptical this would actually get merged though
There's only one way to find out :)
Please, PR it to Nim @Vindaar, I think it is useful
Ok, so the alternatives are:
I'd go with 1 tbh, but I admit I'm not a day-to-day python user, so I might be missing smth.
Closing this since no objections. Feel free to bring more arguments though.
@yglukhov Hopefully we can reconsider this, because we can't define iter and next to implement a Python iterator without supporting the names of the magic methods.
The magic/dunder methods rely on identifiers with underscores incompatible with Nim identifiers. Below is an example of a common interaction with Python context managers where a slight workaround is needed to invoke such methods.
This works just fine, but it seems like this could be a spot for some convenience wrapper/convention for dealing with Python context managers. Any thoughts on anything nimpy might want to support?