[issue44276] Replace if-elif-else structure with match-case (PEP634)

2021-06-04 Thread Kshitiz Arya
Kshitiz Arya added the comment: As Brandt shows us, match-case in its current implementation is not significantly different from an if-else ladder in term of performance, though I still maintain that match-case is much more readable than an if-else ladder. I also agree with Karthikeyan and T

[issue44276] Replace if-elif-else structure with match-case (PEP634)

2021-06-04 Thread Terry J. Reedy
Terry J. Reedy added the comment: To me, Raymond's flattening is a plausible replacement, especially ater a future speedup. However, I would re-order the patterns to None, False, True, str(), int(), ..., _. These independent conditions, other than _ (or else in the if chain), can be ordere

[issue44276] Replace if-elif-else structure with match-case (PEP634)

2021-06-02 Thread Brandt Bucher
Brandt Bucher added the comment: Hm, that benchmark seems really noisy. Looking at your code, it appears that you aren't actually iterating over the results. I've attached a version of your benchmark rewritten to use pyperf. Here are the results on a system with a fresh PGO/LTO build of CPyt

[issue44276] Replace if-elif-else structure with match-case (PEP634)

2021-06-02 Thread Kshitiz Arya
Kshitiz Arya added the comment: I have used timeit module. I have also attached the test file with this message -- Added file: https://bugs.python.org/file50081/match_test.py ___ Python tracker _

[issue44276] Replace if-elif-else structure with match-case (PEP634)

2021-06-02 Thread Steven D'Aprano
Steven D'Aprano added the comment: How did you do the timing? -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscri

[issue44276] Replace if-elif-else structure with match-case (PEP634)

2021-06-02 Thread Kshitiz Arya
Kshitiz Arya added the comment: I have timed the execution of if-else and match-case on Differ().compare from difflib module and here is what I got When both strings are same ** if-else: 2.5049004761

[issue44276] Replace if-elif-else structure with match-case (PEP634)

2021-06-01 Thread Raymond Hettinger
Raymond Hettinger added the comment: In difflib, there's an example where it would be easy to run performance tests. match tag: case 'replace': g = self._fancy_replace(a, alo, ahi, b, blo, bhi) case 'delete': g

[issue44276] Replace if-elif-else structure with match-case (PEP634)

2021-06-01 Thread Raymond Hettinger
Raymond Hettinger added the comment: If the json.encoder code does get updated, it doesn't need two levels of matching. It can be flattened by eliminating the *chunks* variable. match value: case str(): yield _encoder(value) case None: yield 'null'

[issue44276] Replace if-elif-else structure with match-case (PEP634)

2021-06-01 Thread Kshitiz Arya
Kshitiz Arya added the comment: I guess we will have to wait until Python 3.10 is released and we have more conclusive data about speed and readability of match-case before we can go ahead with this issue. -- ___ Python tracker

[issue44276] Replace if-elif-else structure with match-case (PEP634)

2021-06-01 Thread Steven D'Aprano
Steven D'Aprano added the comment: match-case has not even reached a stable version of Python yet, it is only available in Python 3.10 which is still in beta. Are we sure that it is faster in all cases and how do you know it is more intuitive when the vast majority of Python users have likel

[issue44276] Replace if-elif-else structure with match-case (PEP634)

2021-06-01 Thread Kshitiz Arya
Kshitiz Arya added the comment: This is a relatively simple example of how this will improve readability of the code. (This example is form Lib/json/encoder.py) Original - if isinstance(value, str): yield _en

[issue44276] Replace if-elif-else structure with match-case (PEP634)

2021-06-01 Thread Kshitiz Arya
Kshitiz Arya added the comment: Pardon my ignorance here but can I start working on this issue? I am a new contributor therefore I am unsure about how to proceed from here -- ___ Python tracker

[issue44276] Replace if-elif-else structure with match-case (PEP634)

2021-05-31 Thread Brandt Bucher
Change by Brandt Bucher : -- nosy: +brandtbucher ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail

[issue44276] Replace if-elif-else structure with match-case (PEP634)

2021-05-31 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: This is done on a case by case basis and in places necessary in future code. Modifying existing code can pollute git history, make backports hard, might introduce subtle bugs etc. This is similar to proposal to use walrus operator, f-strings, etc.

[issue44276] Replace if-elif-else structure with match-case (PEP634)

2021-05-31 Thread Kshitiz Arya
New submission from Kshitiz Arya : Replace if-elif-else with match-case for pattern matching, which is generally faster and more intuitive. -- components: Library (Lib) messages: 394839 nosy: Kshitiz17 priority: normal severity: normal status: open title: Replace if-elif-else structure