[Python-Dev] Re: Request for comments on final version of PEP 653 (Precise Semantics for Pattern Matching)

2021-03-31 Thread Mark Shannon
Hi Brandt, On 30/03/2021 11:49 pm, Brandt Bucher wrote: Hi Mark. I've spoken with Guido, and we are willing to propose the following amendments to PEP 634: - Require `__match_args__` to be a tuple. I think we're all in agreement on this one. Let's just do it. - Add new `__match_seq__` and

[Python-Dev] Weird io.OpenWrapper hack to use a function as method

2021-03-31 Thread Victor Stinner
Hi, The io module provides an open() function. It also provides an OpenWrapper which only exists to be able to store open as a method (class or instance method). In the _pyio module, pure Python implementation of the io module, OpenWrapper is implemented as: class OpenWrapper: """Wrapper for

[Python-Dev] Re: Weird io.OpenWrapper hack to use a function as method

2021-03-31 Thread Victor Stinner
tl; dr *Maybe* staticmethod could be modified to become callable? io.open is a built-in function (type "builtin_function_or_method"). It behaves differently than _pyio.open which is a Python function (type "function"). The difference is in the LOAD_METHOD bytecode which uses __get__() descriptor

[Python-Dev] Re: Weird io.OpenWrapper hack to use a function as method

2021-03-31 Thread Victor Stinner
A friend, Antoine Rozo, wrote a variant of staticmethod which is callable. With this decorator, it works in A, B and C cases: --- class simplefunction: def __init__(self, func): self.func = func def __get__(self, owner, instance): return self.func def __call__(self, *arg

[Python-Dev] Re: PEP-376 and PEP-427 interpretation

2021-03-31 Thread Daniel Holth
I meant to exclude md5 and sha1, e.g. hash functions with known problems. SHA224 would be a weird choice but it wouldn't personally offend me otherwise. It would be fun to see how many wheel handlers support non-sha256 hash functions. On Mon, Mar 29, 2021 at 9:56 PM Theallredman via Python-Dev < p

[Python-Dev] Re: Weird io.OpenWrapper hack to use a function as method

2021-03-31 Thread Ethan Furman
On 3/31/21 6:49 AM, Victor Stinner wrote: tl; dr *Maybe* staticmethod could be modified to become callable? There have been other requests to make staticmethod callable, one of them being https://bugs.python.org/issue20309 +1 for having it done. -- ~Ethan~

[Python-Dev] Re: Weird io.OpenWrapper hack to use a function as method

2021-03-31 Thread Victor Stinner
I created https://bugs.python.org/issue43682 "Make static methods created by @staticmethod callable". Oh, I didn't know this old bpo-20309 issue closed as "not a bug". But it proposed to modify many other wrappers like @classmethod. I only propose to make static methods created @staticmethod calla

[Python-Dev] Re: Weird io.OpenWrapper hack to use a function as method

2021-03-31 Thread Guido van Rossum
Honestly it has always bugged me that staticmethod only becomes callable through __get__. So I think this would be fine. But I don't know if there might be unintended consequences. ___ Python-Dev mailing list -- python-dev@python.org To unsubscribe send a

[Python-Dev] Re: Weird io.OpenWrapper hack to use a function as method

2021-03-31 Thread Barry Scott
> On 31 Mar 2021, at 13:34, Victor Stinner wrote: > > def func(): >print("my func") This would work for the example given of a func with no args. But cannot check it called with the right number. def func(*args): print("my func") A signature like this would be a hard nut to crack. d

[Python-Dev] Re: SC feedback: PEP 648 -- Extensible customizations of the interpreter at startup

2021-03-31 Thread Mario Corchero
Thanks all. I'll address this feedback next week. Regards, Mario On Wed, 31 Mar 2021 at 03:01, Barry Warsaw wrote: > Kind of :) > > PEP 648 would definitely allow us to deprecate the executable part of pth > files. I let my own biases leak in to my response because I would like to > find a way

[Python-Dev] Re: Request for comments on final version of PEP 653 (Precise Semantics for Pattern Matching)

2021-03-31 Thread Adrian Freund
Hi Mark, I also wanted to give some feedback on this. While most of the discussion so far has been about the matching of the pattern itself I think it should also be considered what happens in the block below. Consider this code: ``` m = ... match m:     case [a, b, c] as l:         # what can

[Python-Dev] Re: Request for comments on final version of PEP 653 (Precise Semantics for Pattern Matching)

2021-03-31 Thread Guido van Rossum
On Wed, Mar 31, 2021 at 2:30 AM Mark Shannon wrote: > > - Add new `__match_seq__` and `__match_map__` special attributes, > corresponding to new public `Py_TPFLAGS_MATCH_SEQ` and > `Py_TPFLAGS_MATCH_MAP` flags for use in `tp_flags`. When Python classes are > defined with one or both of these attr

[Python-Dev] Re: Request for comments on final version of PEP 653 (Precise Semantics for Pattern Matching)

2021-03-31 Thread Mark Shannon
Hi Guido, On 31/03/2021 6:21 pm, Guido van Rossum wrote: On Wed, Mar 31, 2021 at 2:30 AM Mark Shannon > wrote: > - Add new `__match_seq__` and `__match_map__` special attributes, corresponding to new public `Py_TPFLAGS_MATCH_SEQ` and `Py_TPFLAGS_MATCH_MAP` fl

[Python-Dev] Re: Request for comments on final version of PEP 653 (Precise Semantics for Pattern Matching)

2021-03-31 Thread Guido van Rossum
On Wed, Mar 31, 2021 at 12:08 PM Mark Shannon wrote: > Hi Guido, > > On 31/03/2021 6:21 pm, Guido van Rossum wrote: > > On Wed, Mar 31, 2021 at 2:30 AM Mark Shannon > > wrote: > > [Brandt Bucher, earlier] > > > - Add new `__match_seq__` and `__match_map__` special a

[Python-Dev] Re: Request for comments on final version of PEP 653 (Precise Semantics for Pattern Matching)

2021-03-31 Thread Brandt Bucher
>> - Add new `__match_seq__` and `__match_map__` special attributes, >> corresponding to new public `Py_TPFLAGS_MATCH_SEQ` and >> `Py_TPFLAGS_MATCH_MAP` flags for use in `tp_flags`. When Python classes are >> defined with one or both of these attributes set to a boolean value, >> `type.__new__`

[Python-Dev] Re: Request for comments on final version of PEP 653 (Precise Semantics for Pattern Matching)

2021-03-31 Thread Guido van Rossum
On Wed, Mar 31, 2021 at 2:14 PM Brandt Bucher wrote: > (One change from my last email: it doesn't allow `__match_map__` / > `__match_seq__` to be set to `False`... only `True`. This prevents some > otherwise tricky multiple-inheritance edge-cases present in both of our > flagging systems that I d

[Python-Dev] Re: Request for comments on final version of PEP 653 (Precise Semantics for Pattern Matching)

2021-03-31 Thread Brandt Bucher
Guido van Rossum wrote: > On Wed, Mar 31, 2021 at 2:14 PM Brandt Bucher brandtbuc...@gmail.com > wrote: > > (One change from my last email: it doesn't allow `__match_map__` / > > `__match_seq__` to be set to `False`... only `True`. This prevents some > > otherwise tricky multiple-inheritance edge-c

[Python-Dev] Re: Request for comments on final version of PEP 653 (Precise Semantics for Pattern Matching)

2021-03-31 Thread Caleb Donovick
> Here, `Child` will *not* match as a sequence, even though it probably should, Strong disagree, if I explicitly set `__match_seq__` to `False` in `Parent` I probably have a good reason for it and would absolutely expect `Child` to not match as a sequence. > - Raise at class definition time if i

[Python-Dev] Re: Request for comments on final version of PEP 653 (Precise Semantics for Pattern Matching)

2021-03-31 Thread Chris Angelico
On Thu, Apr 1, 2021 at 11:54 AM Caleb Donovick wrote: > > > Here, `Child` will *not* match as a sequence, even though it probably > > should, > > Strong disagree, if I explicitly set `__match_seq__` to `False` in `Parent` > I probably have a good reason for it and would absolutely expect `Child

[Python-Dev] Re: Weird io.OpenWrapper hack to use a function as method

2021-03-31 Thread Inada Naoki
Do we need _pyio at all? Does PyPy or any other Python implementation use it? On Wed, Mar 31, 2021 at 9:36 PM Victor Stinner wrote: > > Hi, > > The io module provides an open() function. It also provides an > OpenWrapper which only exists to be able to store open as a method > (class or instance

[Python-Dev] Re: Request for comments on final version of PEP 653 (Precise Semantics for Pattern Matching)

2021-03-31 Thread Caleb Donovick
> It's a stronger statement than simply undoing > the declaration that it's a sequence. There would be no way to reset > to the default state. How is this different from anything else that is inherited? The setting of a flag to `False` is not some irreversible process which permanently blocks chi

[Python-Dev] Re: Request for comments on final version of PEP 653 (Precise Semantics for Pattern Matching)

2021-03-31 Thread Guido van Rossum
+1. I also don’t see what’s the big deal. On Wed, Mar 31, 2021 at 19:27 Caleb Donovick wrote: > > It's a stronger statement than simply undoing > > the declaration that it's a sequence. There would be no way to reset > > to the default state. > > How is this different from anything else that is

[Python-Dev] Re: Weird io.OpenWrapper hack to use a function as method

2021-03-31 Thread Brett Cannon
On Wed., Mar. 31, 2021, 18:56 Inada Naoki, wrote: > Do we need _pyio at all? > Does PyPy or any other Python implementation use it? > https://www.python.org/dev/peps/pep-0399/ would suggest rolling back Python support is something to avoid. > On Wed, Mar 31, 2021 at 9:36 PM Victor Stinner > w