[issue20632] Define a new __key__ protocol

Nick Coghlan report at bugs.python.org
Tue Feb 13 02:27:18 EST 2018


Nick Coghlan <ncoghlan at gmail.com> added the comment:

It isn't InitVar that you want for that use case (that's just for passing extra information to __post_init__).

Instead, you want:

    extra_field = field(compare=False): int # Excluded from __hash__, __eq_, etc

You can also exclude a field from __hash__, but keep it in the comparison methods:

    unhashed_field = field(hash=False): int # Excluded from __hash__ only

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue20632>
_______________________________________


More information about the Python-bugs-list mailing list