Commit Graph

26 Commits

Author SHA1 Message Date
Miss Islington (bot) 472997659b
bpo-44662: Add ability to annotate types.Union (GH-27214) (GH-27461)
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
(cherry picked from commit 8182c8329c)

Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
2021-07-30 11:31:54 +02:00
Miss Islington (bot) 8a37e8cf45
bpo-44732: Rename types.Union to types.UnionType (GH-27342)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 2b8ad9e6c5)

Co-authored-by: Hasan <hasan.aleeyev@gmail.com>
2021-07-26 12:02:58 -07:00
Miss Islington (bot) 0aea99e444
bpo-44676: Serialize the union type using only public API (GH-27323) (GH-27340)
Remove also the _from_args() constructor.
(cherry picked from commit 435a0334d3)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-07-24 22:35:33 +03:00
Ken Jin ca5a4cf826
bpo-44731: Simplify the union type implementation (GH-27318) (GH-27334)
Remove direct support of typing types in the C code because they are already supported by defining methods __or__ and __ror__ in the Python code.

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-07-24 15:49:25 +01:00
Pablo Galindo Salgado 9356d1e47d
[3.10] bpo-44676: Add ability to serialize types.Union (GH-27244) (GH-27333)
(cherry picked from commit fe13f0b0f6)

Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
2021-07-24 15:08:53 +01:00
Miss Islington (bot) 21db59fc75
bpo-44653: Support typing types in parameter substitution in the union type. (GH-27247) (#27296)
(cherry picked from commit 2e3744d50b)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-07-23 00:18:49 +02:00
Miss Islington (bot) 85b58292cf
bpo-44633: Fix parameter substitution of the union type with wrong types. (GH-27218) (GH-27224)
A TypeError is now raised instead of returning NotImplemented.
(cherry picked from commit 3ea5332a43)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-07-18 14:59:25 +03:00
Miss Islington (bot) 03aad3049d
[3.10] bpo-44654: Refactor and clean up the union type implementation (GH-27196) (GH-27219)
(cherry picked from commit 0fd27375ca)
2021-07-18 00:10:21 +03:00
Serhiy Storchaka 2d055ce132
[3.10] bpo-44490: Add __parameters__ and __getitem__ to types.Union (GH-26980) (GH-27207)
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>.
(cherry picked from commit c45fa1a5d9)

Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
2021-07-17 22:14:57 +03:00
Serhiy Storchaka 80844d1ebc
[3.10] bpo-44652: Preserve natural order of args in the union type. (GH-27185) (GH-27190)
(cherry picked from commit 0cd2d51aad)

Automerge-Triggered-By: GH:ambv
2021-07-16 06:42:04 -07:00
Serhiy Storchaka c3007ab3c6
[3.10] bpo-44636: Collapse union of equal types (GH-27178) (GH-27181)
The result of `int | int` is now `int`.

Fix comparison of the union type with non-hashable objects.
`int | str == {}` no longer raises a TypeError.
(cherry picked from commit d9f923280f)
2021-07-16 14:48:20 +03:00
Miss Islington (bot) 705988056e
bpo-44646: Fix the hash of the union type. (GH-27179) (#27180)
It no longer depends on the order of arguments.
hash(int | str) == hash(str | int)

Co-authored-by: Jack DeVries <58614260+jdevries3133@users.noreply.github.com>
(cherry picked from commit aeaa553d65)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-07-16 11:02:59 +02:00
Miss Islington (bot) cc1a47c849
bpo-44632: Fix support of TypeVar in the union type (GH-27139) (GH-27143)
int | TypeVar('T') returns now an instance of types.Union
instead of typing.Union.
(cherry picked from commit a158b20019)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-07-15 10:25:22 +03:00
Serhiy Storchaka 6dec525582
[3.10] bpo-44635: Convert None to NoneType in the union type constructor (GH-27136). (GH-27142)
(cherry picked from commit b81cac0560)
2021-07-15 10:15:14 +03:00
Miss Islington (bot) b42eee78e7
bpo-44606: Fix __instancecheck__ and __subclasscheck__ for the union type. (GH-27120)
* Fix issubclass() for None.
  E.g. issubclass(type(None), int | None) returns now True.
* Fix issubclass() for virtual subclasses.
  E.g. issubclass(dict, int | collections.abc.Mapping) returns now True.
* Fix crash in isinstance() if the check for one of items raises exception.
(cherry picked from commit 81989058de)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-07-13 21:55:45 -07:00
Miss Islington (bot) 000b9e803a
bpo-44553: Correct failure in tp_new for the union object (GH-27008) (GH-27009)
(cherry picked from commit bc39614856)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
2021-07-03 21:51:10 +01:00
Miss Islington (bot) 0856134542
bpo-44553 : Implement GC methods for types.Union (GH-26993)
(cherry picked from commit 1097384ce9)

Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
2021-07-03 06:33:16 -07:00
Miss Islington (bot) 7e6cad7e30
bpo-44483: Fix crash in union object with bad ``__module__`` (GH-26848) (GH-26852)
(cherry picked from commit adfa1ba398)

Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
2021-06-23 12:38:49 +03:00
Ken Jin 49cd68fb1e
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
2021-01-02 08:19:15 -08:00
kj 463c7d3d14
bpo-42195: Ensure consistency of Callable's __args__ in collections.abc and typing (GH-23060) 2020-12-13 10:38:24 -08:00
kj 4eb41d055e
bpo-42233: Add union type expression support for GenericAlias and fix de-duplicating of GenericAlias (GH-23077) 2020-11-08 20:00:13 -08:00
Neil Schemenauer 0564aafb71
bpo-42099: Fix reference to ob_type in unionobject.c and ceval (GH-22829)
* Use Py_TYPE() rather than o->ob_type.
2020-10-27 18:55:52 +00:00
Serhiy Storchaka 98c4433a81
bpo-41991: Remove _PyObject_HasAttrId (GH-22629)
It can silence arbitrary exceptions.
2020-10-10 22:23:42 +03:00
Victor Stinner d73cf7ca85
bpo-41428: Fix compiler warning in unionobject.c (GH-22416)
Use Py_ssize_t type rather than int, to store lengths in
unionobject.c. Fix the warning:

Objects\unionobject.c(205,1): warning C4244: 'initializing':
conversion from 'Py_ssize_t' to 'int', possible loss of data
2020-09-26 12:48:41 +02:00
Victor Stinner d67de0a30d
bpo-41428: Fix compiler warnings in unionobject.c (GH-22388)
Use Py_ssize_t type rather than int, to store lengths in
unionobject.c. Fix warnings:

Objects\unionobject.c(189,71): warning C4244: '+=':
conversion from 'Py_ssize_t' to 'int', possible loss of data

Objects\unionobject.c(182,1): warning C4244: 'initializing':
conversion from 'Py_ssize_t' to 'int', possible loss of data

Objects\unionobject.c(205,1): warning C4244: 'initializing':
conversion from 'Py_ssize_t' to 'int', possible loss of data

Objects\unionobject.c(437,1): warning C4244: 'initializing':
conversion from 'Py_ssize_t' to 'int', possible loss of data
2020-09-23 23:25:54 +02:00
Maggie Moss 1b4552c5e8
bpo-41428: Implementation for PEP 604 (GH-21515)
See https://www.python.org/dev/peps/pep-0604/ for more information.

Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
2020-09-09 21:23:24 +01:00