Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/writing-plugins/generating-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@ It also emits `# ruff: noqa` to suppress linting on generated code, and
Use the `no_fmt_off` option (see [Options](./options.md#no_fmt_off)) to omit
`# fmt: off` if you want ruff to format the output.

If the generated code references deprecated members, pass

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to detect when deprecated members have been referenced, and emit the directive automatically? It's unfortunate that we have to add in a plugin option for this.

@anuraaga anuraaga Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in a great way - the biggest reason is this is a string printer with a bit of pythonic functionality, not an AST-builder etc type of thing. So a user can just string interpolate some reference (e.g., connect-py generates a full function signature with a potentially deprecated RPC method as a single string) and we have no way of knowing that. On top of that, without an AST we can't determine if a deprecated thing is being referenced or just declared, the latter would cause a lint error on unused suppression. And while types may be closer to being detectable, fields are even harder.

Our of curiosity, FWIU protobuf-es generates @deprecated, I'm guessing it is checked by eslint etc so suppressing lint globally (similar to how we suppress ruff globally) handles it, here it's type-checker so we need type-checker suppression here, with unused suppressions themselves flagged.

`suppress_deprecated=True` to also emit directives that stop pyright and ty from
reporting it:

```python
f.preamble(desc, suppress_deprecated=True)
```

Only pass it when needed, since ty reports the directive as unused otherwise.

!!! note
Every `.py` file also has `from __future__ import annotations` inserted
automatically — with or without a preamble.
21 changes: 7 additions & 14 deletions examples/plugin/tests/gen/user/v1/user_pb.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions examples/protobuf/src/example/gen/example_pb.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 11 additions & 15 deletions packages/bench/src/bench/gen/buffa/bench_messages_pb.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions packages/bench/src/bench/gen/buffa/benchmarks_pb.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading