On Fri, Sep 6, 2019 at 4:12 AM Andrew Barnert <abarn...@yahoo.com> wrote: > > On Sep 5, 2019, at 02:15, Chris Angelico <ros...@gmail.com> wrote: > > > > On Thu, Sep 5, 2019 at 7:08 PM Andrew Barnert via Python-ideas > > <python-ideas@python.org> wrote: > >> > >> Which means if they run into a situation where they’re checking types of a > >> zillion objects, they’re definitely not going to guess that it’s 5x as > >> slow, so there definitely going to misuse it. > >> > > > > Hang on hang on.... what's this situation where you're checking types > > of a zillion objects? > > Exception was the first one I thought of, but, as you argue, that’s a bit of > a special case. And my next thought was the kind of thing you’d do with > pattern matching in a different language but which would be more naturally > (and often more efficiently) done with method calls (or maybe > @singledispatch) in Python. > > But here’s an example from the stdlib, in the json module: > > `elif isinstance(value, …):` ... with a tuple today (to special-case list and > tuple). > > But the fact that I found an example in the stdlib in 2 minutes of searching > implies that this probably isn’t nearly as rare as you’d at first expect. >
We need an implementation to benchmark before we can be sure, but part of my "hang on" was that, even when there ARE lots of objects to check, a single isinstance per object is a vanishingly small part of the overall job. I suppose you might find a performance regression on json.dumps([[]]*10000) but the other costs are normally going to dominate it. In any case, though, the Union type can itself be special-cased inside isinstance to make this efficient again (as Steven showed), which means this is highly unlikely to be "5x as slow", and making this entire subtread fairly moot :) (As a side effect of this change, I wouldn't be sorry to bypass the grammatical ambiguity (from history) of the comma in an except clause. Currently "except Exc1, Exc2:" is a syntax error, but "except Exc1|Exc2:" would be perfectly valid.) ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/E5BY2SOFPA7F5FOG7LJTIL2PK4U32F4C/ Code of Conduct: http://python.org/psf/codeofconduct/