Author thepabloaguilar
Recipients thepabloaguilar
Date 2021-07-13.03:34:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1626147288.08.0.390931510004.issue44617@roundup.psfhosted.org>
In-reply-to
Content
Hey, I'm not sure if this is really a bug but I'd like to show to prevent some undesired behavior!

I'm working in the `match` support for returns (https://github.com/dry-python/returns) library when I saw a behavior similar to the described in `Constant Value Patterns` section on PEP-622 (https://www.python.org/dev/peps/pep-0622/#constant-value-patterns).

A very small and reproducible example:
```python
from typing import Any, ClassVar, Optional


class Maybe:
    empty: ClassVar['Maybe']
    _instance: Optional['Maybe'] = None

    def __new__(cls, *args: Any, **kwargs: Any) -> 'Maybe':
        if cls._instance is None:
            cls._instance = object.__new__(cls)
        return cls._instance


Maybe.empty = Maybe()


if __name__ == '__main__':
    my_maybe = Maybe()
    match my_maybe:
        case Maybe.empty:
            print('FIRST CASE')
        case _:
            print('DEFAULT CASE')
```

The output here is `FIRST CASE`, but if I delete `__new__` method the output is `DEFAULT CASE`.

Is that the correct behavior?

Python version: 3.10.0a7
History
Date User Action Args
2021-07-13 03:34:48thepabloaguilarsetrecipients: + thepabloaguilar
2021-07-13 03:34:48thepabloaguilarsetmessageid: <1626147288.08.0.390931510004.issue44617@roundup.psfhosted.org>
2021-07-13 03:34:48thepabloaguilarlinkissue44617 messages
2021-07-13 03:34:47thepabloaguilarcreate