¶How Black Handles Comments When Python's Grammar Ignores Them
Python's official grammar does not include comments in its AST. This article is a nice description of how Black (the Python linter) stores comments without having to make invasive (and hard to verify) changes to the AST structure.
How Black Handles Comments When Python's Grammar Ignores Them