On Sat, Apr 3, 2021 at 4:20 AM Mark Shannon <m...@hotpy.org> wrote: > 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 > > [...] > > -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. >
Okay, now we're talking. If you check it on both class definition and at attribute assignment time I think that's fine (now that it's a tuple). But I don't think the specification (in whatever PEP) needs to specify that it *must* be checked at that time. So I think the current implementation is fine as well (once we change it to accept only tuples). > 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. > Yeah, nice optimization. > 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. > Well, usually that is The Python Way. There are a lot of things that could be detected statically quite easily (without building something like mypy) but that aren't. Often that's due to historical accidents (in the past we were even less able to do the simplest static checks), so it's fine to do this your way. BTW we previously discussed whether `__match_args__` can contain duplicates. I thought the PEP didn't state either way, but I was wrong: it explicitly disallows it, matching the implementation. PEP 634 says on line 503: ``` - For duplicate keywords, ``TypeError`` is raised. ``` Given that there is no inconsistency here, I am inclined to keep it that way. If we find a better use case to allow duplicates we can always loosen up the implementation; it's not so simple the other way around. FWIW I am also submitting https://github.com/python/peps/pull/1909 to make `__match_args__` a tuple only, which we all seems to agree on. -- --Guido van Rossum (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/TCRU227DPZ5YMDO7EO5RUV354VUAW4OY/ Code of Conduct: http://python.org/psf/codeofconduct/