It's an interesting idea. This sounds like the wrong solution to me, though: it's significant extra machinery to produce a solution that only fixes a small handful of cases; IOW, the benefit / cost ratio seems to small to make this worth it. E.g., apart from the function calls that you mention, what about expressions? "-0x8000" isn't a numeric literal, so the 'original representation' information attached to "0x8000" will have been lost.
I'm also sceptical that this can be done as simply as you describe: isn't the AST no longer available at the time that the docstring is built?
Perhaps what we need instead is a general mechanism to override the generated signature line? |