[PATCH 01 of 10] check-code: add AST check for mutable default argument values

Jun Wu quark at fb.com
Fri Dec 30 12:29:23 EST 2016

Excerpts from Augie Fackler's message of 2016-12-28 12:18:51 -0500:
> >  - Slower, extra tests and GCs (especially in a tight loop)
> Py_None will at worst get decref'd. It’s a singleton, so there won’t be
> any extra GC’ing. `is` checks in cpython are extremely fast (they’re exact
> pointer comparisons, so they’re bafflingly cheap compared to pretty much
> any other Python operation).

It's the empty list or dict getting created and GCed.

> Ehhh, I’m pretty deeply uncomfortable putting more magic in our AST
> transformer. I’ve still got a vision of how we can make some blame
> improvements and then actually do a one-time conversion of things like
> string constants and drop the AST mangler.

How about having an frozenemptydict constant in the codebase and use it as
default parameter? The idea is to directly make the object immutable,
without using "workaround"s like "is None" etc.

More information about the Mercurial-devel mailing list