Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove suggestions to use deprecated type hints (List, Dict, Type, etc.) #6783

Open
DFEvans opened this issue Dec 17, 2024 · 5 comments
Open
Assignees
Labels
needs repro Issue has not been reproduced yet

Comments

@DFEvans
Copy link

DFEvans commented Dec 17, 2024

Is your feature request related to a problem? Please describe.
As of Python 3.9, a large number of typing.Foo imports are deprecated: https://docs.python.org/3/library/typing.html#deprecated-aliases

The deprecations generally fall into two categories:

  • Use foo[x] rather than typing.Foo[x]
  • Use collections.abc.Foo rather than typing.Foo

Describe the solution you’d like
Hint text should refer to the new versions, at least in Python versions that support them. I can't find a clear statement of what Python versions are currently supported, but I suspect that no in-support Python 3 versions are incompatible with list[str].

For example, when I write the incorrect type(T), I should be told to use type[T], not Type[T]: https://github.com/microsoft/pyright/blob/d22c8004f225eeaa28bdb4a06d979eeb38171b12/packages/pyright-internal/src/localization/package.nls.en-us.json#L2078-L2081

Image

@erictraut
Copy link
Contributor

Pyright has a configuration option called deprecateTypingAliases that marks these symbols as deprecated. You can also combine this with reportDeprecated if you want to mark these as errors.

If you want the completion suggestions to avoid suggesting these deprecated symbols, that would require some additional logic in the language server code. The language server features for pyright are maintained by the Microsoft pylance team.

Could someone from the pylance team please transfer this enhancement request to the pylance-release project and triage/prioritize it as you see fit? Thanks!

@erictraut
Copy link
Contributor

@rchiodo, @debonte

@rchiodo rchiodo transferred this issue from microsoft/pyright Dec 17, 2024
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Dec 17, 2024
@rchiodo
Copy link
Contributor

rchiodo commented Dec 17, 2024

To be sure I understand, the request here is to eliminate this option from completions (and other similar types):

Image

Seems unnecessary to me. You typed in the upper case version. We provided it to you.

It doesn't show up if you use lower case lis:

Image

And the error is there in case you don't realize you shouldn't use the upper case version anymore.

@DFEvans
Copy link
Author

DFEvans commented Dec 18, 2024

Ah, sorry, I wasn't very clear - I'd forgotten to appreciate how wide a scope there would be for "you're giving the wrong type hint"!

What I mean are things like this suggestion below. I've written type(T) as a type hint, which is incorrect - I should use type[T]. However, the suggestion I'm given is to both:
a) Change () to [], which is the correct solution
b) Change type to Type, which is a poor suggestion as Type is deprecated
It's the b) part that I think is something to fix or improve on.

Image

@erictraut
Copy link
Contributor

Ah, I misinterpreted what you meant. You're referring to the wording of the error message.

The reason the error message suggests Type[T], List[T] and Dict[T] is because the lowercase versions do not work in Python 3.8 or older. Although the upper-case versions are deprecated, it's unlikely that they'll ever be removed (it would break too much existing code), so it's safe to use them.

In any case, Python 3.8 was recently EOL'ed (about a month ago), so I think it's reasonable to change the error message to refer to the lowercase version.

I've made that change in the pyright code base.

erictraut added a commit to microsoft/pyright that referenced this issue Dec 18, 2024
…` rather than their deprecated uppercase counterparts now that Python 3.8 is EOL'ed. This addresses microsoft/pylance-release#6783.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro Issue has not been reproduced yet
Projects
None yet
Development

No branches or pull requests

4 participants