Message 403560 - Python tracker

Message403560

Author saaketp
Recipients GBeauregard, eric.smith, saaketp
Date 2021-10-10.00:02:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1633824171.71.0.905798776141.issue45384@roundup.psfhosted.org>
In-reply-to
Content
Treating Final as ClassVar by default may be fine,
but it should not throw when using default_factory like ClassVar does.

There are valid uses of Final with instance variable when one would want the value to be unchanged after the `__init__` runs
but different instances can be initialized with different values that are generated by a default_factory.

A quick search on github for this pattern gives this
https://github.com/166MMX/hiro-python-library/blob/fb29e3247a8fe1b0f7dc4e68141cf7340a8dd0a5/src/arago/hiro/model/ws.py#L120
which will break if Final throws when using default_factory.

PEP 591 says:
Type checkers should infer a final attribute _that is initialized in a class body_ as being a class variable.
When using default_factory the attribute is not initialized inside the class body but when the instance is initialized.
So allowing instance level Final with default_factory will not be going against the PEP.
History
Date User Action Args
2021-10-10 00:02:51saaketpsetrecipients: + saaketp, eric.smith, GBeauregard
2021-10-10 00:02:51saaketpsetmessageid: <1633824171.71.0.905798776141.issue45384@roundup.psfhosted.org>
2021-10-10 00:02:51saaketplinkissue45384 messages
2021-10-10 00:02:51saaketpcreate