[issue44642] Union of a type and the typing module function

2022-01-22 Thread Nikita Sobolev


Nikita Sobolev  added the comment:

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 "", line 1, in 
TypeError: unsupported operand type(s) for |: 'type' and 'function'

>>> int | typing.get_type_hints
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unsupported operand type(s) for |: 'type' and 'function'
```

--
resolution:  -> fixed
stage:  -> resolved
status: open -> closed

___
Python tracker 

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



[issue44642] Union of a type and the typing module function

2022-01-22 Thread Guido van Rossum


Guido van Rossum  added the comment:

Do you recommend to just close this as "fixed"?

--

___
Python tracker 

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



[issue44642] Union of a type and the typing module function

2022-01-22 Thread Nikita Sobolev


Nikita Sobolev  added the comment:

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 "", line 1, in 
TypeError: unsupported operand type(s) for |: 'type' and 'function'

>>> int | typing.get_type_hints
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unsupported operand type(s) for |: 'type' and 'function' 
```

--
nosy: +sobolevn

___
Python tracker 

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



[issue44642] Union of a type and the typing module function

2021-07-16 Thread Guido van Rossum


Guido van Rossum  added the comment:

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__"?

--

___
Python tracker 

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



[issue44642] Union of a type and the typing module function

2021-07-15 Thread Ken Jin


Ken Jin  added the comment:

@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.

--

___
Python tracker 

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



[issue44642] Union of a type and the typing module function

2021-07-15 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

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.

--

___
Python tracker 

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



[issue44642] Union of a type and the typing module function

2021-07-15 Thread Guido van Rossum


Guido van Rossum  added the comment:

Is it worth being picky about this? The internal data structures are safe. A 
static checker will complain. What more do you need?

--

___
Python tracker 

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



[issue44642] Union of a type and the typing module function

2021-07-15 Thread Serhiy Storchaka


New submission from Serhiy Storchaka :

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).

--
components: Interpreter Core
messages: 397528
nosy: gvanrossum, kj, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Union of a type and the typing module function
versions: Python 3.10, Python 3.11

___
Python tracker 

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