This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author martinitus
Recipients gvanrossum, kj, martinitus, serhiy.storchaka
Date 2021-11-01.10:36:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1635762982.71.0.136253440992.issue45665@roundup.psfhosted.org>
In-reply-to
Content
One thing that probably should be considered in this context:

isinstance(arg, type) == issubclass(type(arg), type)

Holds True for arg in (Optional[X], Union[X, Y]). Both sides evaluate to False. (v3.10.0)

While I still think both sides evaluating to True would be more intuitive, this supports the proposed change.

Small test snippet:

```
from typing import Dict, List, Set, Tuple, Optional, Union

import pytest


@pytest.mark.parametrize('arg', [
    list, List[int], list[int],
    dict, Dict[str, int], dict[str, int],
    set, Set[int], set[int],
    tuple, Tuple[str, int], tuple[str, int],
    Optional[int],
    Union[int, str]
])
def test_invariant(arg):
    same = isinstance(arg, type) == issubclass(type(arg), type)
    result = "Check" if same else "Failed"
    print(f"\n{result}: Testing: {arg=} with {type(arg)=}: {isinstance(arg, type)=} <> {issubclass(type(arg), type)=}")
    assert same

```

Any other commonly used annotations that could be added to the checklist?
History
Date User Action Args
2021-11-01 10:36:22martinitussetrecipients: + martinitus, gvanrossum, serhiy.storchaka, kj
2021-11-01 10:36:22martinitussetmessageid: <1635762982.71.0.136253440992.issue45665@roundup.psfhosted.org>
2021-11-01 10:36:22martinituslinkissue45665 messages
2021-11-01 10:36:22martinituscreate