On Wed, May 26, 2021 at 02:09:58AM +1000, Chris Angelico wrote:

> Remember: The thing that you declare Final will, some day, need to be
> changed. Probably as part of your own test suite (you do have one of
> those, right?). With MyPy, you could tell it not to validate that
> line, or that file. With a naming convention, you can explain the need
> for the change with a comment. How are you going to override the
> language feature?

That depends on how it is implemented. Here are some thoughts. Given:

    constant spam = "spam and eggs"

we might be able to change it like this:

    # Rebinding a constant raises a warning. Just ignore the warning.
    try:
        spam = "spam spam spam spam"
    except Warning:
        pass

    # Write directly to the namespace.
    globals()['spam'] = "spam spam spam spam"

    # Command line switch or environment variable.
    python3.11 --no-constants testsuite.py

    # Context manager.
    with ConstantEnforcement(False):
        spam = "spam spam spam spam"

    # Special backdoor.
    sys.setconstant('spam', "spam spam spam spam")


Enforcing constantness doesn't necessarily imply there is no way to 
disable or work around it. Especially in a consenting adults language 
like Python, I would expect that there will be.

(Most likely just write directly to the namespace.)



-- 
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/V7VHVJOA3M7CAGJTAO3SKGGMRWBKLTIV/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to