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

[Downgrade] - Returning self no longer has proper type annotations #1927

Closed
iann838 opened this issue Oct 10, 2021 · 6 comments
Closed

[Downgrade] - Returning self no longer has proper type annotations #1927

iann838 opened this issue Oct 10, 2021 · 6 comments
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@iann838
Copy link

iann838 commented Oct 10, 2021

Today I noticed something is wrong with the annotation of codes, lot of codes and variables are marked as Any (white color), I have iterated the possible cause of this can it was due to return self in an async method defined in parent classes. It does not annotate properly self when it is extended, it keeps annotating self as the parent class. See image:

image

Note: this only happens to async methods, non-async methods works as expected.

Environment data

Language server version: 2021.10.0
Pylance version: v2021.10.0
Python version: 3.8.7
OS: win10

Expected behaviour

Variable o in image is annotated as B instead of ~A

Actual behaviour

Variable o in image is annotated as ~A

Impact potential

it basically disables the ability of autocompletion after using a parent defined async method returning self, because it is annotated as the parent class, it does not have access to extended class attributes.

Code snippet of the image

class A:

    async def get(self):
        return self


class B(A):
    pass


async def run():
    o = await B().get()
    o

Temporary Fix

EDIT: Downgrading Pylance to version v2021.9.4 fixes this aswell. Peraphs the easiest fix

from typing import TypeVar

Self = TypeVar('Self')

class A:

    async def get(self: Self) -> Self:
        return self

This does not justify as a "expected behavior", it functions with normal python methods but not coroutine methods

@iann838
Copy link
Author

iann838 commented Oct 10, 2021

I have edited the issue, but it might not be visible enough, adding it here:
Downgrading Pylance to version v2021.9.4 fixes this aswell. Peraphs the easiest fix

@iann838 iann838 changed the title [Downgrade] - Returning self no longer has proper autocompletions [Downgrade] - Returning self no longer has proper type annotations Oct 10, 2021
@erictraut
Copy link
Contributor

Thanks for the bug report. I've created a tracking bug in the pyright repo, and I'll investigate further.

@erictraut
Copy link
Contributor

This will be fixed in the next release.

@erictraut erictraut added bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed triage labels Oct 10, 2021
@iann838
Copy link
Author

iann838 commented Oct 11, 2021

@erictraut Thanks, may I know when will next release be ? Will close after I update the version and check the bug is fixed

@erictraut
Copy link
Contributor

We release pylance weekly, typically on Wednesdays.

We'll close the issue once the new version is published.

@bschnurr
Copy link
Member

This issue has been fixed in version 2021.10.1, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#2021101-14-october-2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants