Skip to content
New issue

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

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

Already on GitHub? # to your account

PEP 702's @deprecated, @overload, and __new__() #8574

Closed
finite-state-machine opened this issue Jul 28, 2024 · 1 comment
Closed

PEP 702's @deprecated, @overload, and __new__() #8574

finite-state-machine opened this issue Jul 28, 2024 · 1 comment
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working

Comments

@finite-state-machine
Copy link

finite-state-machine commented Jul 28, 2024

Describe the bug
Changes associated with #4456 add support for much of PEP 702, but the implementation currently fails to warn about use of a @deprecated @overload of __new__().

This is being filed as a separate issue (rather than a comment on #4456) at @erictraut's request.

Code or Screenshots

pyright-play.net

from __future__ import annotations

# pyright: strict

from typing import (
        Union,
        overload,
        )

from typing_extensions import (
        Self,
        deprecated,
        )


class ClassWithInit:

    @overload
    def __init__(self, value: int, /) -> None: ...
    @deprecated("passing strings is deprecated")
    @overload
    def __init__(self, value: str, /) -> None: ...

    def __init__(self, value: Union[int, str], /) -> None:
        pass

class ClassWithNew:

    @overload
    def __new__(cls, value: int, /) -> Self: ...
    @deprecated("passing strings is deprecated")
    @overload
    def __new__(cls, value: str, /) -> Self: ...

    def __new__(cls, value: Union[int, str], /) -> Self:
        return super().__new__(cls)


ClassWithInit(42)           # no error, as expected
ClassWithInit('forty-two')  # "The constructor for class 'ClassWithInit' is deprecated" as expected
ClassWithNew(42)            # no error, as expected
ClassWithNew('forty-two')   # got: no error; expected: similar error to above

VS Code extension or command-line
Pyright command-line 1.1.373

@finite-state-machine finite-state-machine added the bug Something isn't working label Jul 28, 2024
erictraut added a commit that referenced this issue Jul 28, 2024
…during a class constructor call. This addresses #8574.
@erictraut erictraut added the addressed in next version Issue is fixed and will appear in next published version label Jul 28, 2024
@erictraut
Copy link
Collaborator

This is addressed in pyright 1.1.374.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants