Hi Guido,

On 02/04/2021 10:05 pm, Guido van Rossum wrote:
On Fri, Apr 2, 2021 at 12:43 PM Brandt Bucher <brandtbuc...@gmail.com <mailto:brandtbuc...@gmail.com>> wrote:

    Mark Shannon wrote:
     > On 02/04/2021 7:19 am, Brandt Bucher wrote:
     > > I agree that self-matching classes should absolutely allow
    keyword matches. I had no idea the PEP forbade it.
     > PEP 634 allows it.

    PEP 634 says:

     > For a number of built-in types (specified below), a single
    positional subpattern is accepted which will match the entire
    subject; for these types no keyword patterns are accepted.

    (https://www.python.org/dev/peps/pep-0634/#class-patterns
    <https://www.python.org/dev/peps/pep-0634/#class-patterns>)


But that's not what the implementation does. It still supports keyword patterns for these types -- and (as I've said earlier in this thread) I think the implementation is correct.

     > Most checks are cheap though.
     > Checking for duplicates in `__match_args__` can be done at class
    creation time, and checking for duplicates in the pattern can be
    done at compile time.

    I assume the compile-time check only works for named keyword
    attributes. The current implementation already does this.

    -1 on checking `__match_args__` anywhere other than the match block
    itself.


Agreed.

Why? (I also asked Brandt this)

It is far more efficient to check `__match_args__` at class creation (or class attribute assignment) time.

The most efficient way to check in the match block is to check at class creation time anyway and store a flag whether `__match_args__` is legal. In the match block we would check this flag, then proceed.

It seems silly to know that there will be a runtime error, but not act on that information, allowing latent bugs could have been reported.

Cheers,
Mark.


--
--Guido van Rossum (python.org/~guido <http://python.org/~guido>)
/Pronouns: he/him //(why is my pronoun here?)/ <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>

_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/S45E7DCDXU2LTBSNYYXSIDH6CL7CVDIK/
Code of Conduct: http://python.org/psf/codeofconduct/

_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/EN25PHRQO55AORYWL5SB63JMLVFT6V2L/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to