Message405427
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? |
|
Date |
User |
Action |
Args |
2021-11-01 10:36:22 | martinitus | set | recipients:
+ martinitus, gvanrossum, serhiy.storchaka, kj |
2021-11-01 10:36:22 | martinitus | set | messageid: <1635762982.71.0.136253440992.issue45665@roundup.psfhosted.org> |
2021-11-01 10:36:22 | martinitus | link | issue45665 messages |
2021-11-01 10:36:22 | martinitus | create | |
|