[issue45665] Problems caused by isinstance(list[int], type) returning True

2022-01-06 Thread Alex Waygood


Alex Waygood  added the comment:

> We will still allow instantiating e.g. list[int], right?

I certainly hope so! That would be a much more breaking change if we were to 
change that, and I can't personally see any benefit to doing so.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45665] Problems caused by isinstance(list[int], type) returning True

2022-01-05 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
nosy:  -pablogsal

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45665] Problems caused by isinstance(list[int], type) returning True

2022-01-05 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:

Gentle ping, as the next alpha will be release soon

--
nosy: +pablogsal

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45665] Problems caused by isinstance(list[int], type) returning True

2022-01-04 Thread Guido van Rossum


Guido van Rossum  added the comment:

I now agree with Serhiy's plan. We should execute ASAP so people get a chance 
to try this in the next alpha release.

We will still allow instantiating e.g. list[int], right?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45665] Problems caused by isinstance(list[int], type) returning True

2022-01-04 Thread Alex Waygood


Alex Waygood  added the comment:

I agree with Serhiy.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45665] Problems caused by isinstance(list[int], type) returning True

2022-01-04 Thread Alex Waygood


Alex Waygood  added the comment:

Yes, there are a few exceptions to that :(

```
>>> from typing import Annotated
>>> x = Annotated[int, "idk some int"]
>>> x()
0
>>> isinstance(x, type)
False
>>>
>>> from re import Pattern
>>> y = Pattern[str]
>>> y()
Traceback (most recent call last):
  File "", line 1, in 
TypeError: cannot create 're.Pattern' instances
>>> isinstance(y, type)
True
```

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45665] Problems caused by isinstance(list[int], type) returning True

2022-01-04 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

My plan was to fix as much bugs in the stdlib and backport workaround to 3.9 
and 3.10, then propose to revert this "feature" in 3.11.

There is a risk of introducing some regressions by this change, but we can 
handle it. I think it is better to do it now and fix potential bugs in 
third-party code (we cannot add workarounds in all third-party code) than keep 
this weird special case forever.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45665] Problems caused by isinstance(list[int], type) returning True

2022-01-04 Thread Guido van Rossum


Guido van Rossum  added the comment:

Okay, so it is probably here to stay. We could justify it (after the fact :-) 
by saying that you can instantiate list[int], but not Any.

Are there exceptions to that? (I.e. are there other annotation types that have 
isinstance(X, type) return False but can be instantiated, or the other way 
around?)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45665] Problems caused by isinstance(list[int], type) returning True

2022-01-04 Thread Alex Waygood


Alex Waygood  added the comment:

`isinstance(list[int], type)` returns `True` in 3.9 as well, so the behaviour 
has been around for a while. (Not a comment on whether the change is worth 
making, just a note.)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45665] Problems caused by isinstance(list[int], type) returning True

2022-01-04 Thread Guido van Rossum


Guido van Rossum  added the comment:

So is it too late to change this? This went out with 3.10, Serhiy has argued 
it's a bugfix.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45665] Problems caused by isinstance(list[int], type) returning True

2022-01-04 Thread Ken Jin


Ken Jin  added the comment:

> It does seem inconsistent that Any is not considered a type but list[int] is

Yeah, almost none of the typing "types" are types ever since PEP 560. 
Issue45755 was a side effect too.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45665] Problems caused by isinstance(list[int], type) returning True

2021-12-27 Thread Joseph Perez


Joseph Perez  added the comment:

There is also https://bugs.python.org/issue44293 about inspect.isclass

--
nosy: +joperez

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45665] Problems caused by isinstance(list[int], type) returning True

2021-12-24 Thread Guido van Rossum


Guido van Rossum  added the comment:

See https://github.com/python/mypy/issues/9773#issuecomment-1000975000. I may 
have talked myself into agreeing with Serhiy there! It does seem inconsistent 
that Any is not considered a type but list[int] is:

>>> isinstance(list[int], type)
True
>>> import typing
>>> isinstance(typing.Any, type)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45665] Problems caused by isinstance(list[int], type) returning True

2021-12-11 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
dependencies: +functools' singledispatch does not support GenericAlias

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45665] Problems caused by isinstance(list[int], type) returning True

2021-12-10 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
dependencies:  -functools' singledispatch does not support GenericAlias

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45665] Problems caused by isinstance(list[int], type) returning True

2021-12-10 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
dependencies: +functools' singledispatch does not support GenericAlias

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45665] Problems caused by isinstance(list[int], type) returning True

2021-12-10 Thread Alex Waygood


Alex Waygood  added the comment:

#46032 is related to this issue.

--
nosy: +AlexWaygood

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45665] Problems caused by isinstance(list[int], type) returning True

2021-11-01 Thread Martin Rueckl


Martin Rueckl  added the comment:

Sorry for the noise: 
- Literal['a', 'b'],
- TypeVar('T')
Behave like Optional/Union

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45665] Problems caused by isinstance(list[int], type) returning True

2021-11-01 Thread Martin Rueckl


Martin Rueckl  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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45665] Problems caused by isinstance(list[int], type) returning True

2021-10-29 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
title: Problems caused by isinstance(list[int]) returning True -> Problems 
caused by isinstance(list[int], type) returning True

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com