[issue42345] Equality of typing.Literal depends on the order of arguments

2021-10-13 Thread Ken Jin


Ken Jin  added the comment:

@Alick yes. To be specific, 3.9.1 and above. 3.9.0 still has the old
behavior.

--

___
Python tracker 

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



[issue42345] Equality of typing.Literal depends on the order of arguments

2021-10-12 Thread Alick Zhao


Alick Zhao  added the comment:

Mainly to clarify, this is fixed in Python 3.9 and above, but won't be fixed in 
Python 3.8, right?

```
~$ python3.8
Python 3.8.11 (default, Jul 24 2021, 13:24:12)
[Clang 12.0.5 (clang-1205.0.22.11)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Could not open PYTHONSTARTUP
FileNotFoundError: [Errno 2] No such file or directory: 
'/Users/taoz/.pythonstartup'
>>> from typing import Literal
>>> Literal[1,2]==Literal[2,1]
False
>>>
```

--
nosy: +alick

___
Python tracker 

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



[issue42345] Equality of typing.Literal depends on the order of arguments

2020-11-20 Thread Guido van Rossum


Change by Guido van Rossum :


--
resolution:  -> fixed
stage: patch review -> 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



[issue42345] Equality of typing.Literal depends on the order of arguments

2020-11-20 Thread Yurii Karabas


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

Looks like everything merged, we can close this issue

--

___
Python tracker 

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



[issue42345] Equality of typing.Literal depends on the order of arguments

2020-11-19 Thread miss-islington


miss-islington  added the comment:


New changeset 1051ca4d974ebb6448f58b661aa28f8aff325ed3 by Miss Islington (bot) 
in branch '3.9':
bpo-42345: Add whatsnew and versionchanged for typing.Literal in 3.9 (GH-23386)
https://github.com/python/cpython/commit/1051ca4d974ebb6448f58b661aa28f8aff325ed3


--

___
Python tracker 

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



[issue42345] Equality of typing.Literal depends on the order of arguments

2020-11-19 Thread Guido van Rossum


Guido van Rossum  added the comment:

Thanks everyone! Can I close this now?

--

___
Python tracker 

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



[issue42345] Equality of typing.Literal depends on the order of arguments

2020-11-19 Thread miss-islington


Change by miss-islington :


--
pull_requests: +22304
pull_request: https://github.com/python/cpython/pull/23411

___
Python tracker 

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



[issue42345] Equality of typing.Literal depends on the order of arguments

2020-11-19 Thread miss-islington


miss-islington  added the comment:


New changeset e1dc0db8c7cb8c4d7343e051ba85146b375bb8e0 by kj in branch 'master':
bpo-42345: Add whatsnew and versionchanged for typing.Literal in 3.9 (GH-23386)
https://github.com/python/cpython/commit/e1dc0db8c7cb8c4d7343e051ba85146b375bb8e0


--

___
Python tracker 

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



[issue42345] Equality of typing.Literal depends on the order of arguments

2020-11-19 Thread miss-islington


miss-islington  added the comment:


New changeset 2acd9d0c6ccf0b4360e3b63beddb97996bcb9bb1 by Miss Islington (bot) 
in branch '3.9':
bpo-42345: Fix hash implementation of typing.Literal (GH-23383)
https://github.com/python/cpython/commit/2acd9d0c6ccf0b4360e3b63beddb97996bcb9bb1


--

___
Python tracker 

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



[issue42345] Equality of typing.Literal depends on the order of arguments

2020-11-19 Thread miss-islington


Change by miss-islington :


--
pull_requests: +22301
pull_request: https://github.com/python/cpython/pull/23408

___
Python tracker 

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



[issue42345] Equality of typing.Literal depends on the order of arguments

2020-11-19 Thread miss-islington


miss-islington  added the comment:


New changeset 1b54077ff6f5c1379e097e9f8e8648da9826d6ec by Yurii Karabas in 
branch 'master':
bpo-42345: Fix hash implementation of typing.Literal (GH-23383)
https://github.com/python/cpython/commit/1b54077ff6f5c1379e097e9f8e8648da9826d6ec


--

___
Python tracker 

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



[issue42345] Equality of typing.Literal depends on the order of arguments

2020-11-18 Thread Ken Jin


Change by Ken Jin :


--
pull_requests: +22279
pull_request: https://github.com/python/cpython/pull/23386

___
Python tracker 

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



[issue42345] Equality of typing.Literal depends on the order of arguments

2020-11-18 Thread Guido van Rossum


Guido van Rossum  added the comment:


New changeset 4687338d0ed46e1f5f5060536becf8a96496bae7 by kj in branch 'master':
bpo-42345: Add whatsnew for typing.Literal in 3.10 (GH-23385)
https://github.com/python/cpython/commit/4687338d0ed46e1f5f5060536becf8a96496bae7


--

___
Python tracker 

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



[issue42345] Equality of typing.Literal depends on the order of arguments

2020-11-18 Thread Ken Jin


Change by Ken Jin :


--
pull_requests: +22278
pull_request: https://github.com/python/cpython/pull/23385

___
Python tracker 

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



[issue42345] Equality of typing.Literal depends on the order of arguments

2020-11-18 Thread Yurii Karabas


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


--
pull_requests: +22275
stage: needs patch -> patch review
pull_request: https://github.com/python/cpython/pull/23383

___
Python tracker 

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



[issue42345] Equality of typing.Literal depends on the order of arguments

2020-11-18 Thread Guido van Rossum


Guido van Rossum  added the comment:

We need to fix this to make __hash__ match __eq__.

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

___
Python tracker 

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



[issue42345] Equality of typing.Literal depends on the order of arguments

2020-11-17 Thread Guido van Rossum

Guido van Rossum  added the comment:

I recommend adding a whatsnew entry too. You can just add it to this issue. 
Interestingly you’ll probably need two separate ones, for 3.9 and 3.10. That 
would become two separate PRs for master, the 3.9 one to be backported.

--
resolution:  -> fixed
stage: patch review -> 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



[issue42345] Equality of typing.Literal depends on the order of arguments

2020-11-17 Thread miss-islington


miss-islington  added the comment:


New changeset ac472b316cbb22ab8b750a474e991b46d1e92e15 by Yurii Karabas in 
branch '3.9':
[3.9] bpo-42345: Fix three issues with typing.Literal parameters (GH-23294) 
(GH-23335)
https://github.com/python/cpython/commit/ac472b316cbb22ab8b750a474e991b46d1e92e15


--

___
Python tracker 

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



[issue42345] Equality of typing.Literal depends on the order of arguments

2020-11-16 Thread Yurii Karabas


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


--
pull_requests: +4
pull_request: https://github.com/python/cpython/pull/23335

___
Python tracker 

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



[issue42345] Equality of typing.Literal depends on the order of arguments

2020-11-16 Thread miss-islington


miss-islington  added the comment:


New changeset f03d318ca42578e45405717aedd4ac26ea52aaed by Yurii Karabas in 
branch 'master':
bpo-42345: Fix three issues with typing.Literal parameters (GH-23294)
https://github.com/python/cpython/commit/f03d318ca42578e45405717aedd4ac26ea52aaed


--
nosy: +miss-islington

___
Python tracker 

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



[issue42345] Equality of typing.Literal depends on the order of arguments

2020-11-15 Thread Guido van Rossum


Guido van Rossum  added the comment:

Yeah, I think it makes sense to de-dupe args for Literal.

--

___
Python tracker 

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



[issue42345] Equality of typing.Literal depends on the order of arguments

2020-11-15 Thread Ken Jin


Ken Jin  added the comment:

@Guido and @Ivan,

Should Literals de-duplicate values in its __args__ similar to Union? PEP 586 
states that:
> Literal[v1, v2, v3] is equivalent to Union[Literal[v1], Literal[v2], 
> Literal[v3]]

Naturally, a Union de-duplicates values, so I was wondering if Literal should 
follow.

--
nosy: +kj

___
Python tracker 

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



[issue42345] Equality of typing.Literal depends on the order of arguments

2020-11-15 Thread Yurii Karabas


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


--
keywords: +patch
nosy: +uriyyo
nosy_count: 3.0 -> 4.0
pull_requests: +22185
stage: needs patch -> patch review
pull_request: https://github.com/python/cpython/pull/23294

___
Python tracker 

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



[issue42345] Equality of typing.Literal depends on the order of arguments

2020-11-13 Thread Guido van Rossum


Guido van Rossum  added the comment:

Probably the implementation focused on static typing, not runtime checking.

Can you come up with a PR for a fix?

--
stage:  -> needs patch
versions: +Python 3.10, Python 3.8

___
Python tracker 

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



[issue42345] Equality of typing.Literal depends on the order of arguments

2020-11-13 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
nosy: +gvanrossum, levkivskyi

___
Python tracker 

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



[issue42345] Equality of typing.Literal depends on the order of arguments

2020-11-13 Thread Dominik V.


New submission from Dominik V. :

[PEP 
586](https://www.python.org/dev/peps/pep-0586/#shortening-unions-of-literals) 
specifies that

Literal[v1, v2, v3]

is equivalent to

Union[Literal[v1], Literal[v2], Literal[v3]]

Since the equality of Unions doesn't take into account the order of arguments, 
Literals parametrized with multiple arguments should not be order dependent 
either. However they seem to:

>>> Literal[1, 2] == Literal[2, 1]
False

Compare with the equivalent form:

>>> Union[Literal[1], Literal[2]] == Union[Literal[2], Literal[1]]
True

In addition to that, the PEP specifies that nested Literals should be 
equivalent to the flattened version 
(https://www.python.org/dev/peps/pep-0586/#legal-parameters-for-literal-at-type-check-time).
 This section is titled "Legal parameters for Literal at type check time" but 
since the PEP doesn't specify runtime behavior differently, I think it makes 
sense to assume it is the same. It seems to be different though:

>>> Literal[Literal[1, 2], 3]
typing.Literal[typing.Literal[1, 2], 3]
>>> Literal[Literal[1, 2], 3] == Literal[1, 2, 3]
False

Also the flattening follows from the above definition `Literal[v1, v2, v3] == 
Union[Literal[v1], Literal[v2], Literal[v3]]` and the fact that Unions are 
flattened.

--
messages: 380888
nosy: Dominik V.
priority: normal
severity: normal
status: open
title: Equality of typing.Literal depends on the order of arguments
type: behavior
versions: Python 3.9

___
Python tracker 

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