
On Mon, Jan 17, 2022 at 7:10 PM Steven D'Aprano <steve@pearwood.info> wrote:
Out of those 29 calls, I think that probably 13 would be good candidates to use a frozenset display form (almost half). For example:
ast.py: binop_rassoc = frozenset(("**",)) # f{("**",)} asyncore.py: ignore_log_types = frozenset({'warning'}) # f{'warning'}
Both are in class scope so the overhead is very small.
Not all of them are purely literals, e.g.
asyncore.py: _DISCONNECTED = frozenset({ECONNRESET, ENOTCONN, ...})
would still have to generate the frozenset at runtime, but it wouldn't need to look up the frozenset name to do so so there would still be some benefit.
Name lookup is faster than building set in most case. So I don't think cost to look name up is important at all. Proposed literal might have significant efficiency benefit only when: * It is used in the function scope. and, * It can not be optimized by the compiler now. I am not sure how many such usages in stdlib. Regards, -- Inada Naoki <songofacandy@gmail.com>