diff options
author | Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> | 2021-01-03 00:19:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-02 08:19:15 -0800 |
commit | 49cd68fb1ed4cbaf109308c0a7c8c1efcf6f3775 (patch) | |
tree | 4a32be22ada611677a3d9f86b5c1e1215aac3dcd /Objects | |
parent | handle empty string in variable executable in platform.libc_ver() (#23140) (diff) | |
download | cpython-49cd68fb1ed4cbaf109308c0a7c8c1efcf6f3775.tar.gz cpython-49cd68fb1ed4cbaf109308c0a7c8c1efcf6f3775.tar.bz2 cpython-49cd68fb1ed4cbaf109308c0a7c8c1efcf6f3775.zip |
bpo-42195: Disallow isinstance/issubclass for subclasses of genericaliases in Union (GH-24059)
Previously this didn't raise an error. Now it will:
```python
from collections.abc import Callable
isinstance(int, list | Callable[..., str])
```
Also added tests in Union since there were previously none for stuff like ``isinstance(list, list | list[int])`` either.
Backport to 3.9 not required.
Automerge-Triggered-By: GH:gvanrossum
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/unionobject.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Objects/unionobject.c b/Objects/unionobject.c index 32aa5078af..05350363ee 100644 --- a/Objects/unionobject.c +++ b/Objects/unionobject.c @@ -34,7 +34,7 @@ is_generic_alias_in_args(PyObject *args) { Py_ssize_t nargs = PyTuple_GET_SIZE(args); for (Py_ssize_t iarg = 0; iarg < nargs; iarg++) { PyObject *arg = PyTuple_GET_ITEM(args, iarg); - if (Py_TYPE(arg) == &Py_GenericAliasType) { + if (PyObject_TypeCheck(arg, &Py_GenericAliasType)) { return 0; } } |