- Python Home
- About
- News
- Documentation
- Downloads
- Community
- Foundation
- Developer's Guide
- Issue Tracker
- Issues
- Summaries
- User
- Administration
- Help
Issue44642
This issue tracker has been migrated to GitHub,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2021-07-15 07:58 by serhiy.storchaka, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Messages (8) | |||
|---|---|---|---|
| msg397528 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
Date: 2021-07-15 07:58 | |
The union type accepts any function from the typing module: >>> import typing >>> int | typing.cast int | typing.cast >>> int | typing.get_type_hints int | typing.get_type_hints It is a consequence of too lenient check for the typing.NewType() result (which does not work at all with PR 9951). |
|||
| msg397558 - (view) | Author: Guido van Rossum (gvanrossum) * ![]() |
Date: 2021-07-15 15:14 | |
Is it worth being picky about this? The internal data structures are safe. A static checker will complain. What more do you need? |
|||
| msg397569 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
Date: 2021-07-15 16:47 | |
It is only reminder that our test for NewType is arbitrary. And it is not compatible with PR 9951. Possible solutions are: 1. Make NewType a class and add more strict test. Pro -- we can make arbitrary repr, contra -- it has small negative effect on performance. See issue34963. 2. Remove the test for NewType at all and allow or-ing types and arbitrary functions. 3. Introduce a special attribute to distinguish unionable objects. It will make the code of unionobject.c simpler. I lean towards option 1 (not excluding 3). Small performance losses seem inevitable. |
|||
| msg397570 - (view) | Author: Ken Jin (kj) * ![]() |
Date: 2021-07-15 16:56 | |
@Serhiy > 1. Make NewType a class and add more strict test. See also: issue44353 (https://bugs.python.org/issue44353). We had some discussion there about converting to class but it ended in a deadlock. |
|||
| msg397632 - (view) | Author: Guido van Rossum (gvanrossum) * ![]() |
Date: 2021-07-16 15:13 | |
I think making NewType into a class isn't a good idea, it would be too slow. But I like issue34963 (PR 9951). So then let's do some variation on (3) -- unionable things would include all types (of course), typevars, and things that have a special attribute. We could then set that special attribute on the function returned by NewType (like PR 9951 already does for __name__ and __qualname__). What to call it? Maybe "__unionable__"? |
|||
| msg411298 - (view) | Author: Nikita Sobolev (sobolevn) * ![]() |
Date: 2022-01-22 22:50 | |
It does not happen anymore on `main` (3.11): ``` Python 3.11.0a4+ (heads/main-dirty:ef3ef6fa43, Jan 20 2022, 20:48:25) [Clang 11.0.0 (clang-1100.0.33.16)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import typing >>> int | typing.cast Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for |: 'type' and 'function' >>> int | typing.get_type_hints Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for |: 'type' and 'function' ``` |
|||
| msg411330 - (view) | Author: Guido van Rossum (gvanrossum) * ![]() |
Date: 2022-01-23 01:22 | |
Do you recommend to just close this as "fixed"? |
|||
| msg411351 - (view) | Author: Nikita Sobolev (sobolevn) * ![]() |
Date: 2022-01-23 07:25 | |
Looks like it was fixed indeed, `NewType` is now a class. And I cannot reproduce it even on `3.10`: ``` Python 3.10.0 (default, Nov 1 2021, 10:24:06) [Clang 11.0.0 (clang-1100.0.33.16)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import typing >>> int | typing.cast Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for |: 'type' and 'function' >>> int | typing.get_type_hints Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for |: 'type' and 'function' ``` |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:47 | admin | set | github: 88808 |
| 2022-01-23 07:25:17 | sobolevn | set | status: open -> closed resolution: fixed messages: + msg411351 stage: resolved |
| 2022-01-23 01:22:43 | gvanrossum | set | messages: + msg411330 |
| 2022-01-22 22:50:33 | sobolevn | set | nosy:
+ sobolevn messages: + msg411298 |
| 2021-07-20 01:32:57 | kj | link | issue44353 superseder |
| 2021-07-16 15:13:51 | gvanrossum | set | messages: + msg397632 |
| 2021-07-15 16:56:07 | kj | set | messages: + msg397570 |
| 2021-07-15 16:47:27 | serhiy.storchaka | set | messages: + msg397569 |
| 2021-07-15 15:14:43 | gvanrossum | set | messages: + msg397558 |
| 2021-07-15 07:58:18 | serhiy.storchaka | create | |



