Skip to content

Instantly share code, notes, and snippets.

@brumar
Created January 17, 2022 18:14
Show Gist options
  • Select an option

  • Save brumar/76e0b9bf39acd491bbf05650e5757ba9 to your computer and use it in GitHub Desktop.

Select an option

Save brumar/76e0b9bf39acd491bbf05650e5757ba9 to your computer and use it in GitHub Desktop.
fix pyannotate annotations by changing relative paths to absolute paths
import json
from pathlib import Path
if __name__ == "__main__":
dico = json.load(Path("./annotations.json").open())
for element in dico:
element["path"] = str(Path(__file__).parent) + "/" + element["path"]
json.dump(dico, Path("./annotations_2.json").open("w"))
@brumar
Copy link
Author

brumar commented Jan 17, 2022

Very often I get "No files need to be modified" when the annotation files generated by pyannotate contains many annotations. This is probably related to my usage of pytest-annotate that does not mesh well with pyannotate. I don't know the root cause to be honest. This gist produce a file named annotations_2.json that have absolute paths in it, so that my pyannotate --type-info ./annotations_2.json --py3 -p -w . work at last.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment