| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4629c22 commit 448d7b9
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -858,7 +858,7 @@ A literal pattern corresponds to most | |||
| 858 | 858 | : | "None" | |
| 859 | 859 | : | "True" | |
| 860 | 860 | : | "False" | |
| 861 | - signed_number: ["-"] NUMBER | ||
| 861 | + signed_number: ["+" | "-"] NUMBER | ||
| 862 | 862 | ||
| 863 | 863 | The rule ``strings`` and the token ``NUMBER`` are defined in the | |
| 864 | 864 | :doc:`standard Python grammar <./grammar>`. Triple-quoted strings are | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -645,6 +645,10 @@ Other language changes | |||
| 645 | 645 | * Allow the *count* argument of :meth:`bytes.replace` to be a keyword. | |
| 646 | 646 | (Contributed by Stan Ulbrych in :gh:`147856`.) | |
| 647 | 647 | ||
| 648 | + * Unary plus is now accepted in :keyword:`match` literal patterns, mirroring | ||
| 649 | + the existing support for unary minus. | ||
| 650 | + (Contributed by Bartosz Sławecki in :gh:`145239`.) | ||
| 651 | + | ||
| 648 | 652 | ||
| 649 | 653 | New modules | |
| 650 | 654 | =========== | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -554,17 +554,20 @@ complex_number[expr_ty]: | |||
| 554 | 554 | ||
| 555 | 555 | signed_number[expr_ty]: | |
| 556 | 556 | | NUMBER | |
| 557 | + | '+' number=NUMBER { number } | ||
| 557 | 558 | | '-' number=NUMBER { _PyAST_UnaryOp(USub, number, EXTRA) } | |
| 558 | 559 | ||
| 559 | 560 | signed_real_number[expr_ty]: | |
| 560 | 561 | | real_number | |
| 562 | + | '+' real=real_number { real } | ||
| 561 | 563 | | '-' real=real_number { _PyAST_UnaryOp(USub, real, EXTRA) } | |
| 562 | 564 | ||
| 563 | 565 | real_number[expr_ty]: | |
| 564 | 566 | | real=NUMBER { _PyPegen_ensure_real(p, real) } | |
| 565 | 567 | ||
| 566 | 568 | imaginary_number[expr_ty]: | |
| 567 | 569 | | imag=NUMBER { _PyPegen_ensure_imaginary(p, imag) } | |
| 570 | + | '+' imag=NUMBER { _PyPegen_ensure_imaginary(p, imag) } | ||
| 568 | 571 | ||
| 569 | 572 | capture_pattern[pattern_ty]: | |
| 570 | 573 | | target=pattern_capture_target { _PyAST_MatchAs(NULL, target->v.Name.id, EXTRA) } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,6 +18,8 @@ extend-exclude = [ | |||
| 18 | 18 | "test_lazy_import/__init__.py", | |
| 19 | 19 | "test_lazy_import/data/*.py", | |
| 20 | 20 | "test_lazy_import/data/**/*.py", | |
| 21 | + # Unary plus literal pattern is not yet supported by Ruff (GH-145239) | ||
| 22 | + "test_patma.py", | ||
| 21 | 23 | ] | |
| 22 | 24 | ||
| 23 | 25 | [lint] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2762,6 +2762,96 @@ def test_patma_255(self): | |||
| 2762 | 2762 | self.assertEqual(y, 1) | |
| 2763 | 2763 | self.assertIs(z, x) | |
| 2764 | 2764 | ||
| 2765 | + def test_patma_256(self): | ||
| 2766 | + x = 0 | ||
| 2767 | + match x: | ||
| 2768 | + case +0: | ||
| 2769 | + y = 0 | ||
| 2770 | + self.assertEqual(x, 0) | ||
| 2771 | + self.assertEqual(y, 0) | ||
| 2772 | + | ||
| 2773 | + def test_patma_257(self): | ||
| 2774 | + x = 0 | ||
| 2775 | + match x: | ||
| 2776 | + case +0.0: | ||
| 2777 | + y = 0 | ||
| 2778 | + self.assertEqual(x, 0) | ||
| 2779 | + self.assertEqual(y, 0) | ||
| 2780 | + | ||
| 2781 | + def test_patma_258(self): | ||
| 2782 | + x = 0 | ||
| 2783 | + match x: | ||
| 2784 | + case +0j: | ||
| 2785 | + y = 0 | ||
| 2786 | + self.assertEqual(x, 0) | ||
| 2787 | + self.assertEqual(y, 0) | ||
| 2788 | + | ||
| 2789 | + def test_patma_259(self): | ||
| 2790 | + x = 0 | ||
| 2791 | + match x: | ||
| 2792 | + case +0.0j: | ||
| 2793 | + y = 0 | ||
| 2794 | + self.assertEqual(x, 0) | ||
| 2795 | + self.assertEqual(y, 0) | ||
| 2796 | + | ||
| 2797 | + def test_patma_260(self): | ||
| 2798 | + x = 1 | ||
| 2799 | + match x: | ||
| 2800 | + case +1: | ||
| 2801 | + y = 0 | ||
| 2802 | + self.assertEqual(x, 1) | ||
| 2803 | + self.assertEqual(y, 0) | ||
| 2804 | + | ||
| 2805 | + def test_patma_261(self): | ||
| 2806 | + x = 1.5 | ||
| 2807 | + match x: | ||
| 2808 | + case +1.5: | ||
| 2809 | + y = 0 | ||
| 2810 | + self.assertEqual(x, 1.5) | ||
| 2811 | + self.assertEqual(y, 0) | ||
| 2812 | + | ||
| 2813 | + def test_patma_262(self): | ||
| 2814 | + x = 1j | ||
| 2815 | + match x: | ||
| 2816 | + case +1j: | ||
| 2817 | + y = 0 | ||
| 2818 | + self.assertEqual(x, 1j) | ||
| 2819 | + self.assertEqual(y, 0) | ||
| 2820 | + | ||
| 2821 | + def test_patma_263(self): | ||
| 2822 | + x = 1.5j | ||
| 2823 | + match x: | ||
| 2824 | + case +1.5j: | ||
| 2825 | + y = 0 | ||
| 2826 | + self.assertEqual(x, 1.5j) | ||
| 2827 | + self.assertEqual(y, 0) | ||
| 2828 | + | ||
| 2829 | + def test_patma_264(self): | ||
| 2830 | + x = 0.25 + 1.75j | ||
| 2831 | + match x: | ||
| 2832 | + case +0.25 + 1.75j: | ||
| 2833 | + y = 0 | ||
| 2834 | + self.assertEqual(x, 0.25 + 1.75j) | ||
| 2835 | + self.assertEqual(y, 0) | ||
| 2836 | + | ||
| 2837 | + def test_patma_265(self): | ||
| 2838 | + x = 0.25 - 1.75j | ||
| 2839 | + match x: | ||
| 2840 | + case 0.25 - +1.75j: | ||
| 2841 | + y = 0 | ||
| 2842 | + self.assertEqual(x, 0.25 - 1.75j) | ||
| 2843 | + self.assertEqual(y, 0) | ||
| 2844 | + | ||
| 2845 | + def test_patma_266(self): | ||
| 2846 | + x = 0 | ||
| 2847 | + match x: | ||
| 2848 | + case +1e1000: | ||
| 2849 | + y = 0 | ||
| 2850 | + case 0: | ||
| 2851 | + y = 1 | ||
| 2852 | + self.assertEqual(x, 0) | ||
| 2853 | + self.assertEqual(y, 1) | ||
| 2854 | + | ||
| 2765 | 2855 | def test_patma_runtime_checkable_protocol(self): | |
| 2766 | 2856 | # Runtime-checkable protocol | |
| 2767 | 2857 | from typing import Protocol, runtime_checkable | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + Unary plus is now accepted in :keyword:`match` literal patterns, mirroring | ||
| 2 | + the existing support for unary minus. | ||
| 3 | + Patch by Bartosz Sławecki. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments