[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-07-26 Thread Łukasz Langa

Łukasz Langa  added the comment:


New changeset 4a5457d5d48e6563ec481daad245ff3d6ef13503 by Miss Islington (bot) 
in branch '3.10':
bpo-44490: Add 'Whats New' docs regarding types.Union changes (GH-27215) 
(GH-27368)
https://github.com/python/cpython/commit/4a5457d5d48e6563ec481daad245ff3d6ef13503


--

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-07-26 Thread miss-islington


Change by miss-islington :


--
pull_requests: +25906
pull_request: https://github.com/python/cpython/pull/27368

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-07-26 Thread Łukasz Langa

Łukasz Langa  added the comment:


New changeset 6c1b57d958e2b0d5bcf0f2315b5044838e11638f by Yurii Karabas in 
branch 'main':
bpo-44490: Add 'Whats New' docs regarding types.Union changes (GH-27215)
https://github.com/python/cpython/commit/6c1b57d958e2b0d5bcf0f2315b5044838e11638f


--
message_count: 17.0 -> 18.0
nosy: +lukasz.langa
nosy_count: 10.0 -> 11.0
pull_requests: +25906
pull_request: https://github.com/python/cpython/pull/27368

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-07-19 Thread Guido van Rossum


Guido van Rossum  added the comment:


New changeset a2721649598eb715304a1ac8678a409585f73b27 by Ken Jin in branch 
'3.10':
bpo-44490: Improve typing module compatibility with types.Union (GH-27048) 
(#27222)
https://github.com/python/cpython/commit/a2721649598eb715304a1ac8678a409585f73b27


--

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-07-18 Thread Ken Jin


Change by Ken Jin :


--
pull_requests: +25763
pull_request: https://github.com/python/cpython/pull/27222

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-07-17 Thread Ken Jin


Change by Ken Jin :


--
pull_requests:  -25752

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-07-17 Thread miss-islington


Change by miss-islington :


--
nosy: +miss-islington
nosy_count: 9.0 -> 10.0
pull_requests: +25761
pull_request: https://github.com/python/cpython/pull/27220

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-07-17 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:


New changeset 2d055ce13250a4074f66a945381a149a3cf8c46f by Serhiy Storchaka in 
branch '3.10':
[3.10] bpo-44490: Add __parameters__ and __getitem__ to types.Union (GH-26980) 
(GH-27207)
https://github.com/python/cpython/commit/2d055ce13250a4074f66a945381a149a3cf8c46f


--

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-07-17 Thread Yurii Karabas


Change by Yurii Karabas <1998uri...@gmail.com>:


--
pull_requests: +25753
pull_request: https://github.com/python/cpython/pull/27215

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-07-17 Thread Yurii Karabas


Change by Yurii Karabas <1998uri...@gmail.com>:


--
pull_requests: +25752
pull_request: https://github.com/python/cpython/pull/27214

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-07-17 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
nosy: +serhiy.storchaka
nosy_count: 8.0 -> 9.0
pull_requests: +25743
pull_request: https://github.com/python/cpython/pull/27207

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-07-16 Thread Ken Jin


Change by Ken Jin :


--
pull_requests: +25737
pull_request: https://github.com/python/cpython/pull/27203

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-07-16 Thread Guido van Rossum


Change by Guido van Rossum :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed
type:  -> enhancement

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-07-16 Thread Guido van Rossum


Guido van Rossum  added the comment:


New changeset bf89ff96e6ba21bb52b8597b5e51e8ffc57e6589 by Yurii Karabas in 
branch 'main':
bpo-44490: Improve typing module compatibility with types.Union (GH-27048)
https://github.com/python/cpython/commit/bf89ff96e6ba21bb52b8597b5e51e8ffc57e6589


--

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-07-06 Thread Yurii Karabas


Change by Yurii Karabas <1998uri...@gmail.com>:


--
pull_requests: +25604
pull_request: https://github.com/python/cpython/pull/27048

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-07-06 Thread Guido van Rossum


Guido van Rossum  added the comment:


New changeset c45fa1a5d9b419cf13ad4b5a7cb453956495b83e by Yurii Karabas in 
branch 'main':
bpo-44490: Add __parameters__ and __getitem__ to types.Union (GH-26980)
https://github.com/python/cpython/commit/c45fa1a5d9b419cf13ad4b5a7cb453956495b83e


--

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-07-03 Thread ROpdebee


ROpdebee  added the comment:

It also lacks the __module__ attribute, causing it to be unusable in PEP 593 
typing.Annotated types:

from typing import Annotated
x: Annotated[int | str, 'test']

Traceback (most recent call last):
  File "", line 1, in 
  File "/Users/ruben/.pyenv/versions/3.10.0b3/lib/python3.10/typing.py", line 
298, in inner
return cached(*args, **kwds)
  File "/Users/ruben/.pyenv/versions/3.10.0b3/lib/python3.10/typing.py", line 
1594, in __class_getitem__
return _AnnotatedAlias(origin, metadata)
  File "/Users/ruben/.pyenv/versions/3.10.0b3/lib/python3.10/typing.py", line 
1520, in __init__
super().__init__(origin, origin)
  File "/Users/ruben/.pyenv/versions/3.10.0b3/lib/python3.10/typing.py", line 
976, in __init__
self.__module__ = origin.__module__
AttributeError: 'types.Union' object has no attribute '__module__'. Did you 
mean: '__reduce__'?

--
nosy: +ROpdebee

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-07-01 Thread Yurii Karabas


Change by Yurii Karabas <1998uri...@gmail.com>:


--
keywords: +patch
pull_requests: +25542
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/26980

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-06-30 Thread Yurii Karabas


Yurii Karabas <1998uri...@gmail.com> added the comment:

@Ken I will pick up this issue, thanks for asking.

--

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-06-29 Thread Ken Jin


Ken Jin  added the comment:

I don't think we need the types.GenericAlias(int | list[T], str)
workaround. GenericAlias already has code for extracting __parameters__ and
implementing __getitem__. Someone would need to refactor and reuse them for
Union too. That should be enough to trick GenericAlias to treat Union as
another GenericAlias(I don't remember if it checks for __origin__ as well)
and cover other edge cases as well.

@Yurii do you still plan to take this? If not, I'll start working on
something later today.

--

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-06-29 Thread Jelle Zijlstra


Jelle Zijlstra  added the comment:

I'd also be OK with returning a `types.GenericAlias(int | list[T], str)`, which 
might be simpler. It doesn't matter for static type checkers, and runtime type 
checkers can extract what they need anyway.

--

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-06-29 Thread Guido van Rossum


Guido van Rossum  added the comment:

So I guess to expand on Jelle's example, Alias[str] should return (int |
list[str]), right? That makes sense since that's how Union works.

--

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-06-29 Thread Jelle Zijlstra


Jelle Zijlstra  added the comment:

Mypy is definitely not going to support direct access to `__parameters__`; what 
Guido is referring to is whether usage of types.Union that would require 
`__parameters__` at runtime is accepted by mypy.

For example, this:

from typing import TypeVar

T = TypeVar("T")

Alias = int | list[T]

def f(x: Alias[str]) -> None:
pass

But this produces `main.py:7: error: Variable "main.Alias" is not valid as a 
type`: mypy doesn't even recognize `|` as a type yet.

I'd rather not focus too much though on what mypy does; it is one of many type 
checkers by now and does not tend to be the quickest in adding support for new 
features.

Pyright does handle the file above as I'd expect, for what it's worth.

--

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-06-29 Thread Jack DeVries

Jack DeVries  added the comment:

mypy does not support __parameters__:

(venv) ➜  cpython git:(main) cat repro.py 
from typing import TypeVar
T = TypeVar('T')

(int | list[T]).__parameters__
(venv) ➜  cpython git:(main) mypy --version
mypy 0.920+dev.cae5d3c8b5f14d0796914aa6a113473ca3ffc38e
(venv) ➜  cpython git:(main) python --version
Python 3.11.0a0
(venv) ➜  cpython git:(main) mypy repro.py 
repro.py:4: error: "types.Union" has no attribute "__parameters__"
Found 1 error in 1 file (checked 1 source file)
(venv) ➜  cpython git:(main)


mypy also does not support __getitem__

(venv) ➜  cpython git:(main) cat repro.py 
from typing import TypeVar
T = TypeVar('T')

(int | list[T]).__getitem__
(venv) ➜  cpython git:(main) mypy --version
./mypy 0.920+dev.cae5d3c8b5f14d0796914aa6a113473ca3ffc38e
(venv) ➜  cpython git:(main) python --version
Python 3.11.0a0
(venv) ➜  cpython git:(main) mypy repro.py 
repro.py:4: error: Value of type "types.Union" is not indexable
Found 1 error in 1 file (checked 1 source file)
(venv) ➜  cpython git:(main)

--
nosy: +jack__d

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-06-29 Thread Guido van Rossum


Guido van Rossum  added the comment:

I intended for someone to write some test programs and report back here what 
mypy actually supports and what it doesn't.

--

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-06-29 Thread Ken Jin


Ken Jin  added the comment:

Yurii, thanks for the offer.

We only need to implement __getitem__ if union supports TypeVars. Which
means __parameters__ need to be implemented too (or at least a private
internal implementation of it).

I interpreted Guido's message above as to wait and see if static type
checkers even accept things like int | list[T]. Maybe he meant that if that
syntax isnt valid then theres no point for us to implement it? PEP 604
leaves out how it deals with TypeVars, so adding this behavior may require
us to update the PEP first (which will require approval from others).

Anyways, there's no rush. We probably can't backport this so we have until
the next minor release of Python (3.11 or later) to decide.

--

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-06-29 Thread Yurii Karabas


Yurii Karabas <1998uri...@gmail.com> added the comment:

Should `__getitem__` be implemented for `types.Union`?
I can implement it if no one is working on it.

P.S. mypy currently does not support it:
```
Value of type "types.Union" is not indexable
```

--
nosy: +uriyyo

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-06-23 Thread Brandt Bucher


Change by Brandt Bucher :


--
nosy: +brandtbucher

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-06-22 Thread Guido van Rossum


Guido van Rossum  added the comment:

Let's first see whether the type (int | list[T]) is accepted by static checkers.

IMO introspecting unions should be done by looking at __args__, nothing more.

--

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-06-22 Thread Jelle Zijlstra


Jelle Zijlstra  added the comment:

I agree that this is a bug. `types.Union` is also missing a __getitem__ 
implementation.

And `typing.Union` supports pickling while `types.Union` doesn't:

>>> pickle.loads(pickle.dumps(int | str))
Traceback (most recent call last):
  File "", line 1, in 
TypeError: cannot pickle 'types.Union' object
>>> pickle.loads(pickle.dumps(Union[int, str]))
typing.Union[int, str]

I don't have a use case for pickling types but someone might.

--

___
Python tracker 

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



[issue44490] PEP 604 Union (int | str) doesn't have __parameters__

2021-06-22 Thread Ken Jin


New submission from Ken Jin :

Recently I noticed that the new PEP 604 Union type doesn't collect type 
variables:

from typing import TypeVar
T = TypeVar('T')

(int | list[T]).__parameters__

Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'types.Union' object has no attribute '__parameters__'

Whereas the typing.Union version has __parameters__. Is this behavior 
intentional?

The downside to this is that things like this don't work:

alias: TypeAlias = int | list[T]
alias[str] # Error!

--
messages: 396329
nosy: Jelle Zijlstra, gvanrossum, kj, levkivskyi
priority: normal
severity: normal
status: open
title: PEP 604 Union (int | str) doesn't have __parameters__
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