A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/attachments/20160510/0c27b9bd/attachment.html below:

<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, May 10, 2016 at 6:21 AM, Nick Coghlan <span dir="ltr"><<a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 10 May 2016 at 02:30, Guido van Rossum <<a href="mailto:guido@python.org">guido@python.org</a>> wrote:<br>
> On Sun, May 8, 2016 at 7:52 PM, Nick Coghlan <<a href="mailto:ncoghlan@gmail.com">ncoghlan@gmail.com</a>> wrote:<br>
</span><span class="">>> P.S. It occurs to me that a sufficiently sophisticated typechecker<br>
>> might be able to look at all of the calls to "cls(*args, **kwds)" in<br>
>> class methods and "type(self)(*args, **kwds)" in instance methods, and<br>
>> use those to define a set of type constraints for the expected<br>
>> constructor signatures in subclassses, even if the current code base<br>
>> never actually invokes those code paths.<br>
><br>
> Could you restate that as a concrete code example? (Examples of the problems<br>
> with "construction features" would also be helpful, probably -- abstract<br>
> descriptions of problems often lead me astray.)<br>
<br>
</span>Rectangle/Square is a classic example of the constructor signature<br>
changing, so I'll try to use that to illustrate the point with a<br>
"displaced_copy" alternate constructor:<br>
<br>
  Â  class Rectangle:<br>
  Â  Â  Â  def __init__(self, top_left_point, width, height):<br>
  Â  Â  Â  Â  Â  self.top_left_point = top_left_point<br>
  Â  Â  Â  Â  Â  self.width = width<br>
  Â  Â  Â  Â  Â  self.height = height<br>
<br>
  Â  Â  Â  @classmethod<br>
  Â  Â  Â  def displaced_copy(cls, other_rectangle, offset):<br>
  Â  Â  Â  Â  Â  """Create a new instance from an existing one"""<br>
  Â  Â  Â  Â  Â  return cls(other.top_left_point + offset, other.width, other.height)<br></blockquote><div><br></div><div>(But why is it a class method? I guess the example could also use an instance method and it would still have the same properties relevant for this discussion.)<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  Â  class Square:<br>
  Â  Â  Â  def __init__(self, top_left_point, side_length):<br>
  Â  Â  Â  Â  Â  super().__init__(top_left_point, side_length, side_length)<br>
<br>
At this point, a typechecker *could* have enough info to know that<br>
"Square.displaced_copy(some_rectangle, offset)" is necessarily going<br>
to fail, even if nothing in the application actually *calls*<br>
Square.displaced_copy.<br></blockquote></div><br></div><div class="gmail_extra">The question remains of course whether the type checker should flag Square to be an invalid subclass or merely as not implementing displaced_copy().<br><br></div><div class="gmail_extra">Anyway, at this point I believe we're just violently agreeing, so no need for another response. Though Serhiy may be unhappy with the lack of guidance he's received...<br clear="all"></div><div class="gmail_extra"><br>-- <br><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div></div>

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4