<div dir="ltr">Yes, please add this to the PEP in the rejected ideas section, with the motivation for rejection -- the example can show how to work around it.<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 16, 2019 at 12:51 AM Michael Sullivan <<a href="mailto:sully@msully.net">sully@msully.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr">On Mon, Apr 15, 2019 at 8:12 PM Nathaniel Smith <<a href="mailto:njs@pobox.com" target="_blank">njs@pobox.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Mon, Apr 15, 2019 at 5:00 PM Michael Sullivan <<a href="mailto:sully@msully.net" target="_blank">sully@msully.net</a>> wrote:<br>
><br>
> I've submitted PEP 591 (Adding a final qualifier to typing) for discussion to typing-sig [1].<br>
<br>
I'm not on typing-sig [1] so I'm replying here.<br>
<br>
> Here's the abstract:<br>
> This PEP proposes a "final" qualifier to be added to the ``typing``<br>
> module---in the form of a ``final`` decorator and a ``Final`` type<br>
> annotation---to serve three related purposes:<br>
><br>
> * Declaring that a method should not be overridden<br>
> * Declaring that a class should not be subclassed<br>
> * Declaring that a variable or attribute should not be reassigned<br>
<br>
I've been meaning to start blocking subclassing at runtime (e.g. like<br>
[2]), so being able to express that to the typechecker seems like a<br>
nice addition. I'm assuming though that the '@final' decorator doesn't<br>
have any runtime effect, so I'd have to say it twice?<br>
<br>
@typing.final<br>
class MyClass(metaclass=othermod.Final):<br>
    ...<br>
<br>
Or on 3.6+ with __init_subclass__, it's easy to define a @final<br>
decorator that works at runtime, but I guess this would have to be a<br>
different decorator?<br>
<br>
@typing.final<br>
@alsoruntime.final<br>
class MyClass:<br>
    ...<br>
<br>
This seems kinda awkward. Have you considered giving it a runtime<br>
effect, or providing some way for users to combine these two things<br>
together on their own?<br>
<br></blockquote><div>Nothing else in typing does any type of runtime enforcement, so I'd be reluctant to start here.<br></div><div><br></div><div>One approach would be doing something like this (maybe in a support module):</div><div>if typing.TYPE_CHECKING:<br>    from typing import final<br>else:<br></div><div>    from alsoruntime import final</div><div><br></div><div>So that at checking time, the typechecker would use the typing final but at runtime we'd get something that does enforcement.</div><div>(And for the pre-3.6 case, you could maybe use something like six.add_metaclass in order to specify the metaclass as a decorator.)</div><div><br></div><div>I can add this as an example to the PEP.<br></div><div><br></div><div>-sully<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
-n<br>
<br>
[1] <a href="https://github.com/willingc/pep-communication/issues/1" rel="noreferrer" target="_blank">https://github.com/willingc/pep-communication/issues/1</a><br>
[2] <a href="https://stackoverflow.com/a/3949004/1925449" rel="noreferrer" target="_blank">https://stackoverflow.com/a/3949004/1925449</a><br>
<br>
-- <br>
Nathaniel J. Smith -- <a href="https://vorpus.org" rel="noreferrer" target="_blank">https://vorpus.org</a><br>
</blockquote></div></div></div>
_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/guido%40python.org" rel="noreferrer" target="_blank">https://mail.python.org/mailman/options/python-dev/guido%40python.org</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div><div><i style="font-family:Arial,Helvetica,sans-serif;font-size:small;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);color:rgb(136,136,136)"><span>Pronouns</span>: he/him/his </i><a href="http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/" style="color:rgb(17,85,204);font-family:Arial,Helvetica,sans-serif;font-size:small;font-style:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255)" target="_blank"><i>(why is my <span>pronoun</span> here?)</i></a></div></div></div>