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

Wrong warning "Code is Unreachable" when not using await in a async method #325

Closed
deniscapeto opened this issue Sep 4, 2020 · 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

@deniscapeto
Copy link

Environment data

  • Language Server version: v2020.9.0
  • OS and version: Windows 10 - 10.0.19041
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.3

Expected behaviour

Should not show Code is unreachable since the method being called is not awaited

Actual behaviour

image

Code Snippet / Additional information

without any await

import asyncio

class TestUnreachableCode:

    @staticmethod
    async def never_done_task():
        while True:
            await asyncio.sleep(0.01)

    async def test_sould_not_show_unreachable_code(
        self,
        some_object
    ):

        some_object.name = self.never_done_task()

        print('')  # <-- this code should not be marked as unreachable

using await keyword:

import asyncio

class TestUnreachableCode:

    @staticmethod
    async def never_done_task():
        while True:
            await asyncio.sleep(0.01)

    async def test_sould_not_show_unreachable_code(
        self,
        some_object
    ):

        some_object.name = await self.never_done_task()  

        print('')  # <-- It's ok to mark this as unreachable code
@github-actions github-actions bot added the triage label Sep 4, 2020
@deniscapeto deniscapeto changed the title Wrong warning Code is Unreachable when not using await in a async method Wrong warning "Code is Unreachable" when not using await in a async method Sep 4, 2020
@erictraut
Copy link
Contributor

Thanks for the bug report. You're correct that code after such a call should not be marked unreachable. I've disabled the NoReturn logic for all async functions, since it's often difficult or impossible to detect when the async function will execute. With the fix in place, neither of the above examples will report unreachable code. This fix will be in the next version of Pylance and Pyright.

@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 labels Sep 5, 2020
@github-actions github-actions bot removed the triage label Sep 5, 2020
@krooq
Copy link

krooq commented Sep 7, 2020

Somewhat related... re: the latest Pylance changes (v2020.9.0)
Pylance still appears to be hinting Code is unreachable after calls to methods that had NoReturn and now (with the changes) return something else like Any.

I have the latest VSCode and Pylance as of writing.

@erictraut
Copy link
Contributor

@krooq, I'm not sure what you mean. If you think that there's a separate bug, please file a new issue and provide a sample. Thanks!

@krooq
Copy link

krooq commented Sep 7, 2020

@krooq, I'm not sure what you mean. If you think that there's a separate bug, please file a new issue and provide a sample. Thanks!

Ticket raised here, it seems mostly unrelated to this ticket #334

@deniscapeto
Copy link
Author

Thanks for your attention @erictraut

@huguesv
Copy link
Contributor

huguesv commented Sep 11, 2020

This issue has been fixed in version 2020.9.4, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202094-10-september-2020

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

4 participants