twisted / pydoctor

This is pydoctor, an API documentation generator that works by static analysis.
https://pydoctor.readthedocs.io
Other
183 stars 49 forks source link

Format integer literals like the source #294

Open mthuurne opened 3 years ago

mthuurne commented 3 years ago

The source of twisted.internet.posixbase.PosixReactorBase reads:

    def listenUNIX(self, address, factory, backlog=50, mode=0o666, wantPID=0):

But this is formatted in pydoctor as:

    def listenUNIX(self, address, factory, backlog=50, mode=438, wantPID=0):

While decimal 438 is the same value as octal 666, the meaning of 0o666 is immediately clear to someone familiar with POSIX file modes while that is not the case for 438.

The AST does not contain the original formatting of a constant, only the value. However, with accurate line number information we could pick the right slice from the original source file and present that instead.

In theory we could do the same for other literals, but I'm not sure if it would be as useful there as it is for integers.

tristanlatr commented 3 years ago

with accurate line number information we could pick the right slice from the original source file

No idea how you would do that!

This sounds like a very hard task for limited benefits. But maybe I'm mistaken.

tristanlatr commented 2 years ago

We could try to integrate with ASTTokens: https://asttokens.readthedocs.io/en/latest/api-index.html#asttokens.ASTTokens.get_tokens and use it in the colorizer.

This probably means larger refactorings.