mikeshultz/ledger-eth-lib

Default mutable value in transaction model

Closed this issue · 2 comments

We are currently setting an mutable value as a default argument here: https://github.com/mikeshultz/ledger-eth-lib/blob/master/ledgereth/objects.py#L167

This is bad because of reasons like this: https://dollardhingra.hashnode.dev/python-mutable-default-arguments

Basically, the is only one default value, so when you use mutable default values, it is sharing that 1 value around and that can lead some highly unusual outcomes!

To fix it, you can do something like this:

        access_list: List[bytes] = None,
    ):
        access_list = access_list or []

This is really interesting. I've been working with Python for a very long time but don't think I've ever run into this (or noticed 😬). I'm kind of wondering about all my other implementations of this now...