On Mon, Jan 17, 2022 at 7:10 PM Steven D'Aprano <st...@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  <songofaca...@gmail.com>
_______________________________________________
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/GL6KUTJZ67CQ37NK64LJF4XTPAS564OA/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to