Support and render @deprecated with a strike through #2714
Replies: 11 comments 1 reply
-
Are there any standard formats for this in Python? There are quite a few documentation formats, and I'm aware of a number of different decorators for this (including many project-specific ones). |
Beta Was this translation helpful? Give feedback.
-
I'm not aware of any standard way to mark a function, method or class as deprecated. There are a few third-party libraries that offer decorators: I think there's value in supporting something like this, but it probably makes sense only if it is first standardized and included in stdlib, e.g. as part of the typing or functools modules. It loses most of its value if it's not standardized across the Python ecosystem because different tools (linters, type checkers, IDEs) will not work consistently, and there won't be much incentive for adoption within type stubs or libraries. If you're passionate about this idea and want to champion it, I recommend posting a proposal to the typing-sig list. |
Beta Was this translation helpful? Give feedback.
-
It seems to me that any decorator called I'm not suggesting anything more than supporting the same syntax highlighting that the TypeScript Language Server has when it detects a JSDoc comment of There would also be, I believe, no problem with supporting multiple formats or making it configurable. e.g.: have the language server take in I'm asking for language server support and syntax highlighting, not a change to types. |
Beta Was this translation helpful? Give feedback.
-
See also the discussion on microsoft/pyright#2300 and the (just posted) typing-sig thread: https://mail.python.org/archives/list/typing-sig@python.org/thread/E24WTMQUTGKPFKEXVCGGEFFMG7LDF3WT/ |
Beta Was this translation helpful? Give feedback.
-
@erictraut I will agree with @AaronFriel . All we need is @deprecated in the docstring similar to JS solution. This feature is very important in the case of autocomplete modules. We would like to be able to mark the deprecated functions so that the users have a good awareness (with the strike through interface) of what is deprecated. |
Beta Was this translation helpful? Give feedback.
-
@erictraut based on the feedback in the thread, is there a reason this feature has to exist as a PEP within the Python organization and some sort of type-level feature? There are multiple libraries that seek to add some behavior and types or decorators to deprecate things. My suggestion would be: let a thousand flowers bloom and in the language server, support one or several of them, again, solely for the purpose of adding a visual strikethrough. No type checking change, purely visual. Let the decorator libraries do their thing until there's consensus or a PEP, but in the meantime, improve IDE tooling. After all, even if a PEP was approved adding a standard decorator and type annotation, how many years would it be until people stop using the other libraries out there? To me, the suggestion that this needs to go through a PEP and committee process will hold back the Python language server. It adds an enormous amount of process for what could be more rapid iteration. See the As a hypothetical: if someone wanted to add inlay hints to Pyright/Pylance, would that require a PEP? |
Beta Was this translation helpful? Give feedback.
-
Pyright is a standards-based type checker. We generally don't add any type-related functionality to it unless it is either in a standard or in the process of becoming a standard. So, to answer your hypothetical question, the answer is "yes, it would require a PEP". The approach of "letting a thousand flowers bloom" works well for libraries, but it falls apart quickly with programming language features. My advice is for someone who feels strongly about this feature to champion a solution in the typing-sig or python-sig and start the path toward standardization. I'm willing to work with that person and do a reference implementation in pyright as part of the PEP review process. |
Beta Was this translation helpful? Give feedback.
-
I feel like this is a bad comparison, as that is a feature that is fully dependent on the client (it's very close to hover and semantic tokens), whereas deprecation is both something that is visual but also would be exposed in something like a diagnostic that would ban deprecated items. This feature is here #1559, and we have experimented with it. Pyright/pylance have the code to deprecate types like I don't personally think we've eliminated implementing deprecation support without a PEP in Pylance (this issue is not closed!), but having a PEP for deprecation is a very welcomed case that benefits both editors and type checkers alike. Without it, we have to venture into the heuristics of all of the different ways every library and docstring format chooses to deprecate things. |
Beta Was this translation helpful? Give feedback.
-
I agree with Jake that client-only language service features have a different bar for standardization. I may have misinterpreted what you meant by "inlay hints". |
Beta Was this translation helpful? Give feedback.
-
This is not the perspective every language server implementation has applied. What I'm suggesting is narrower and purely client-only. Whether the The following 4 Python packages all define
The intention is clear regardless of implementation. |
Beta Was this translation helpful? Give feedback.
-
Moving this issue to discussion as an enhancement request for comments and upvotes. |
Beta Was this translation helpful? Give feedback.
-
See: https://code.visualstudio.com/updates/v1_49#_deprecated-tag-support-for-javascript-and-typescript
It would be wonderful if this support worked with Pylance in some manner, either via a string in the docstring for a class or an
@deprecated
decorator.Beta Was this translation helpful? Give feedback.
All reactions