➜

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author saaketp
Recipients GBeauregard, eric.smith, saaketp
Date 2021-10-10.00:02:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <[email protected]>
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: <[email protected]>
2021-10-10 00:02:51saaketplinkissue45384 messages
2021-10-10 00:02:51saaketpcreate