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

NoReturn behaving unexpectedly after using the decorator with added type annotation #6391

Closed
Ailitonia opened this issue Sep 15, 2024 · 2 comments
Assignees
Labels
bug Something isn't working fixed in next version (pyright) A fix has been implemented and will appear in an upcoming version

Comments

@Ailitonia
Copy link

Environment data

  • Pylance version: v2024.9.1
  • OS and version: Windows 11 23H2 22631.4169
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.12.5

Code Snippet

from functools import wraps
from typing import Callable, NoReturn


def no_typing_decorator(func):
    @wraps(func)
    def _wrapper(*args, **kwargs):
        return func(*args, **kwargs)
    return _wrapper


def typing_decorator[**P, R](func: Callable[P, R]) -> Callable[P, R]:
    @wraps(func)
    def _wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
        return func(*args, **kwargs)
    return _wrapper


@no_typing_decorator
def no_typing_wrapped_raise_some_exception() -> NoReturn:
    raise RuntimeError


@typing_decorator
def typing_wrapped_raise_some_exception() -> NoReturn:
    raise RuntimeError


def no_typing_test(int_or_str: int | str) -> str:
    if isinstance(int_or_str, int):
        r = no_typing_wrapped_raise_some_exception()

    return int_or_str.strip()  # It's OK, int_or_str: str


def typing_test(int_or_str: int | str) -> str:
    if isinstance(int_or_str, int):
        r = typing_wrapped_raise_some_exception()

    return int_or_str.strip()  # Not fine, int_or_str: int | str

动画3

Repro Steps

  1. input the above code

Expected behavior

The int_or_str variables in lines 33 and 40 both should be recognized as str ​​type

Actual behavior

The int_or_str variables in line 40 still be recognized as int | str ​​type

Logs

Logs
2024-09-15 13:01:19.022 [info] (Client) Pylance async client (2024.9.1) started with python extension (2024.14.1)
2024-09-15 13:01:33.035 [info] (12492) [BG(1)] SemanticTokens full at file:///c%3A/Users/Ailit/Documents/GitHub/omega-miya/foo_decorator.py (0ms)
2024-09-15 13:01:33.272 [info] (12492) [BG(1)] indexing: file:///c%3A/Users/Ailit/Documents/GitHub/omega-miya/foo_decorator.py [found 6] (0ms)
2024-09-15 13:01:33.272 [info] (12492) Indexing Done: file:///c%3A/Users/Ailit/Documents/GitHub/omega-miya/foo_decorator.py
2024-09-15 13:01:33.272 [info] [Info  - 13:01:33] (12492) Heap stats: total_memory_size=65345MB, total_free_size=51697MB, total_heap_size=121MB, used_heap_size=100MB, cross_worker_used_heap_size=100MB, total_physical_size=121MB, total_available_size=3992MB, heap_size_limit=4096MB
2024-09-15 13:01:33.294 [info] (12492) [BG(1)] InlayHints range 0:0 - 40:0 at file:///c%3A/Users/Ailit/Documents/GitHub/omega-miya/foo_decorator.py (0ms)
2024-09-15 13:01:33.775 [info] (12492) [BG(1)] InlayHints range 0:0 - 40:0 at file:///c%3A/Users/Ailit/Documents/GitHub/omega-miya/foo_decorator.py (0ms)
2024-09-15 13:01:33.842 [info] (12492) [BG(1)] InlayHints range 0:0 - 40:0 at file:///c%3A/Users/Ailit/Documents/GitHub/omega-miya/foo_decorator.py (0ms)
2024-09-15 13:01:36.728 [info] (12492) [BG(1)] InlayHints range 0:0 - 40:0 at file:///c%3A/Users/Ailit/Documents/GitHub/omega-miya/foo_decorator.py (0ms)
2024-09-15 13:01:38.547 [info] (12492) [BG(1)] InlayHints range 0:0 - 40:0 at file:///c%3A/Users/Ailit/Documents/GitHub/omega-miya/foo_decorator.py (1ms)
2024-09-15 13:01:39.026 [info] (12492) [BG(1)] InlayHints range 0:0 - 40:0 at file:///c%3A/Users/Ailit/Documents/GitHub/omega-miya/foo_decorator.py (0ms)
2024-09-15 13:01:39.303 [info] (12492) [BG(1)] InlayHints range 0:0 - 40:0 at file:///c%3A/Users/Ailit/Documents/GitHub/omega-miya/foo_decorator.py (0ms)
2024-09-15 13:01:39.369 [info] (12492) [BG(1)] InlayHints range 0:0 - 40:0 at file:///c%3A/Users/Ailit/Documents/GitHub/omega-miya/foo_decorator.py (0ms)
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Sep 15, 2024
erictraut added a commit to microsoft/pyright that referenced this issue Sep 15, 2024
…NoReturn` callable with a function decorator applied. This addresses microsoft/pylance-release#6391.
erictraut added a commit to microsoft/pyright that referenced this issue Sep 15, 2024
…NoReturn` callable with a function decorator applied. This addresses microsoft/pylance-release#6391. (#8996)
@erictraut
Copy link
Contributor

Thanks for the bug report. I'm surprised this bug hasn't been reported previously. It will be fixed in the next release of pyright.

@debonte debonte added bug Something isn't working fixed in next version (pyright) A fix has been implemented and will appear in an upcoming version and removed needs repro Issue has not been reproduced yet labels Sep 15, 2024
@StellaHuang95
Copy link
Contributor

This issue has been fixed in prerelease version 2024.9.101, which we've just released. You can find the changelog here: CHANGELOG.md

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 (pyright) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

5 participants