{"id":13486618,"url":"https://github.com/dropbox/pyannotate","last_synced_at":"2025-03-27T21:30:37.019Z","repository":{"id":37334812,"uuid":"110597280","full_name":"dropbox/pyannotate","owner":"dropbox","description":"Auto-generate PEP-484 annotations","archived":false,"fork":false,"pushed_at":"2022-07-03T08:24:17.000Z","size":182,"stargazers_count":1428,"open_issues_count":35,"forks_count":59,"subscribers_count":26,"default_branch":"master","last_synced_at":"2024-12-17T01:03:38.821Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dropbox.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-13T20:18:08.000Z","updated_at":"2024-12-01T20:17:17.000Z","dependencies_parsed_at":"2022-07-12T11:55:06.579Z","dependency_job_id":null,"html_url":"https://github.com/dropbox/pyannotate","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dropbox%2Fpyannotate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dropbox%2Fpyannotate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dropbox%2Fpyannotate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dropbox%2Fpyannotate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dropbox","download_url":"https://codeload.github.com/dropbox/pyannotate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245927106,"owners_count":20695169,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T18:00:49.139Z","updated_at":"2025-03-27T21:30:36.706Z","avatar_url":"https://github.com/dropbox.png","language":"Python","readme":"PyAnnotate: Auto-generate PEP-484 annotations\n=============================================\n\nInsert annotations into your source code based on call arguments and\nreturn types observed at runtime.\n\nFor license and copyright see the end of this file.\n\nBlog post: http://mypy-lang.blogspot.com/2017/11/dropbox-releases-pyannotate-auto.html\n\nHow to use\n==========\n\nSee also the example directory.\n\nPhase 1: Collecting types at runtime\n------------------------------------\n\n- Install the usual way (see \"red tape\" section below)\n- Add `from pyannotate_runtime import collect_types` to your test\n- Early in your test setup, call `collect_types.init_types_collection()`\n- Bracket your test execution between calls to `collect_types.start()` and\n  `collect_types.stop()` (or use the context manager below)\n- When done, call `collect_types.dump_stats(filename)`\n\nAll calls between the `start()` and `stop()` calls will be analyzed\nand the observed types will be written (in JSON form) to the filename\nyou pass to `dump_stats()`.  You can have multiple start/stop pairs\nper dump call.\n\nIf you'd like to automatically collect types when you run `pytest`,\nsee `example/example_conftest.py` and `example/README.md`.\n\nInstead of using `start()` and `stop()` you can also use a context\nmanager:\n```\ncollect_types.init_types_collection()\nwith collect_types.collect():\n    \u003cyour code here\u003e\ncollect_types.dump_stats(\u003cfilename\u003e)\n```\n\nPhase 2: Inserting types into your source code\n----------------------------------------------\n\nThe command-line tool `pyannotate` can add annotations into your\nsource code based on the annotations collected in phase 1.  The key\narguments are:\n\n- Use `--type-info FILE` to tell it the file you passed to `dump_stats()`\n- Positional arguments are source files you want to annotate\n- With no other flags the tool will print a diff indicating what it\n  proposes to do but won't do anything.  Review the output.\n- Add `-w` to make the tool actually update your files.\n  (Use git or some other way to keep a backup.)\n\nAt this point you should probably run mypy and iterate.  You probably\nwill have to tweak the changes to make mypy completely happy.\n\nNotes and tips\n--------------\n\n- It's best to do one file at a time, at least until you're\n  comfortable with the tool.\n- The tool doesn't touch functions that already have an annotation.\n- The tool can generate either of:\n  - type comments, i.e. Python 2 style annotations\n  - inline type annotations, i.e. Python 3 style annotations, using `--py3` in v1.0.7+\n\nRed tape\n========\n\nInstallation\n------------\n\nThis should work for Python 2.7 as well as for Python 3.4 and higher.\n\n```\npip install pyannotate\n```\n\nThis installs several items:\n\n- A runtime module, pyannotate_runtime/collect_types.py, which collects\n  and dumps types observed at runtime using a profiling hook.\n\n- A library package, pyannotate_tools, containing code that can read the\n  data dumped by the runtime module and insert annotations into your\n  source code.\n\n- An entry point, pyannotate, which runs the library package on your files.\n\nFor dependencies, see setup.py and requirements.txt.\n\nTesting etc.\n------------\n\nTo run the unit tests, use pytest:\n\n```\npytest\n```\n\nTO DO\n-----\n\nWe'd love your help with some of these issues:\n\n- Better documentation.\n- Python 3 code generation.\n- Refactor the tool modules (currently its legacy architecture shines through).\n\nAcknowledgments\n---------------\n\nThe following people contributed significantly to this tool:\n\n- Tony Grue\n- Sergei Vorobev\n- Jukka Lehtosalo\n- Guido van Rossum\n\nLicence etc.\n------------\n\n1. License: Apache 2.0.\n2. Copyright attribution: Copyright (c) 2017 Dropbox, Inc.\n3. External contributions to the project should be subject to\n   Dropbox's Contributor License Agreement (CLA):\n   https://opensource.dropbox.com/cla/\n","funding_links":[],"categories":["Python","资源列表","代码分析和 Lint 工具","Code Analysis","Code Analysis [🔝](#readme)","Tools"],"sub_categories":["代码分析和 Lint 工具","Helper tools to add annotations to existing code"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdropbox%2Fpyannotate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdropbox%2Fpyannotate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdropbox%2Fpyannotate/lists"}