Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Autocomplete for function definition using a TypeAlias is broken #5464

Closed
davidfokkema opened this issue Feb 13, 2024 · 5 comments
Closed

Autocomplete for function definition using a TypeAlias is broken #5464

davidfokkema opened this issue Feb 13, 2024 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@davidfokkema
Copy link

Environment data

  • Language Server version: 2024.2.1 (pyright version 1.1.348, commit cfb1de0c)
  • OS and version: MacOS 14.2.1
  • Python version (& distribution if applicable, e.g. Anaconda): 3.10.1 (from conda environment)

Code Snippet

Consider this definition:

from typing import TypeAlias


Thing: TypeAlias = list[int]

class Base:

    def the_thing(self) -> Thing:
        return []

Repro Steps

  1. Start adding a subclass:
class Child(Base):

    def the_thi
  1. Then, type 'n'.
  2. Note that the floating window shows that the return type is Thing. Screenshot 2024-02-13 at 12 59 45
  3. Hit Tab for autocomplete.
  4. Autocomplete expands the TypeAlias to list[int] instead of Thing.

Expected behavior

Expected output:

class Child(Base):

    def the_thing(self) -> Thing:
        return super().the_thing()

Actual behavior

class Child(Base):

    def the_thing(self) -> list[int]:
        return super().the_thing()

Logs

Could not create the issue with the logs; they were too long although I cleared the log output, enabled the trace setting, pressed n and tab and copied the resulting logs. Not sure what part I'll have to paste from the logs...

@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Feb 13, 2024
@davidfokkema
Copy link
Author

Thanks to @davep for coming up with the MRE code.

@judej judej added bug Something isn't working and removed needs repro Issue has not been reproduced yet labels Feb 21, 2024
@StellaHuang95
Copy link
Contributor

Thank you for reporting this issue. Our current design is to print the original return type instead of the type alias for overridden methods. I don't consider it a bug, but tagging @heejaechang to see if he has a different perspective.

@davidfokkema
Copy link
Author

Thanks, @StellaHuang95! Is there a rationale for this? The tooltip that appears when you are in the process of overriding a method does show the type alias. When you subclass something, you're probably not interested in returning the original type, but in the type alias. You may not even know or understand what the original type is.

@davidfokkema
Copy link
Author

Ran into this problem a few more times while creating subclasses. Whenever I override __init__(), tab completion gives me an elaborate method definition which is unwanted. I get this:

def __init__(
        self,
        *content: Option | Separator | None | ConsoleRenderable | RichCast | str,
        tooltip: ConsoleRenderable | RichCast | str | None = None,
    ):

while this is the original class definition:

    def __init__(
        self,
        *content: NewOptionListContent,
        tooltip: RenderableType | None = None,
    ):

(I removed some other parameters which were simple types and thus unchanged.) Since I just want to subclass something, I don't want the type definition to change. That confuses my users...

@StellaHuang95
Copy link
Contributor

Thanks for the clarification. We could potentially add a setting to control the printed return type to be either original type or type alias. Moving this issue to discussion as an enhancement request for comments and upvotes.

@microsoft microsoft locked and limited conversation to collaborators Jul 22, 2024
@StellaHuang95 StellaHuang95 converted this issue into discussion #6172 Jul 22, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants