Martin Rueckl <eni...@nbubu.de> added the comment:
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? ---------- nosy: +martinitus _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue45665> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com