<html><body>
<p><font size="2" face="sans-serif">Is there a way to overwrite the rule in our hacking (not familiar with it ...)? </font><br>
<font size="2" face="sans-serif">if so ,maybe we can do as suggested to avoid 811 for the class which has Microversion definition? Thanks</font><br>
<br>
<font size="2" face="sans-serif">Best Regards! <br>
<br>
Kevin (Chen) Ji ¼Í ³¿<br>
<br>
Engineer, zVM Development, CSTL<br>
Notes: Chen CH Ji/China/IBM@IBMCN   Internet: jichenjc@cn.ibm.com<br>
Phone: +86-10-82454158<br>
Address: 3/F Ring Building, ZhongGuanCun Software Park, Haidian District, Beijing 100193, PRC </font><br>
<br>
<img width="16" height="16" src="cid:1__=C7BBF748DFC593D08f9e8a93df938@cn.ibm.com" border="0" alt="Inactive hide details for Christopher Yeoh ---01/28/2015 09:37:00 AM---On Tue, 06 Jan 2015 07:31:19 -0500 Jay Pipes <jaypipes@g"><font size="2" color="#424282" face="sans-serif">Christopher Yeoh ---01/28/2015 09:37:00 AM---On Tue, 06 Jan 2015 07:31:19 -0500 Jay Pipes <jaypipes@gmail.com> wrote:</font><br>
<br>
<font size="1" color="#5F5F5F" face="sans-serif">From:      </font><font size="1" face="sans-serif">Christopher Yeoh <cbkyeoh@gmail.com></font><br>
<font size="1" color="#5F5F5F" face="sans-serif">To:        </font><font size="1" face="sans-serif">openstack-dev@lists.openstack.org</font><br>
<font size="1" color="#5F5F5F" face="sans-serif">Date:      </font><font size="1" face="sans-serif">01/28/2015 09:37 AM</font><br>
<font size="1" color="#5F5F5F" face="sans-serif">Subject:   </font><font size="1" face="sans-serif">Re: [openstack-dev] [nova] Questions on pep8 F811 hacking check for microversion</font><br>
<hr width="100%" size="2" align="left" noshade style="color:#8091A5; "><br>
<br>
<br>
<tt><font size="2">On Tue, 06 Jan 2015 07:31:19 -0500<br>
Jay Pipes <jaypipes@gmail.com> wrote:<br>
<br>
> On 01/06/2015 06:25 AM, Chen CH Ji wrote:<br>
> > Based on nova-specs api-microversions.rst<br>
> > we support following function definition format, but it violate the<br>
> > hacking rule pep8 F811 because duplicate function definition<br>
> > we should use #noqa for them , but considering microversion may<br>
> > live for long time ,<br>
> > keep adding #noqa may be a little bit ugly, can anyone suggest a<br>
> > good solution for it ? thanks<br>
> ><br>
> >  >   @api_version(min_version='2.1')<br>
> >  >   def _version_specific_func(self, req, arg1):<br>
> >  >      pass<br>
> >  ><br>
> >  >   @api_version(min_version='2.5')<br>
> >  >   def _version_specific_func(self, req, arg1):<br>
> >  >      pass<br>
> <br>
> Hey Kevin,<br>
> <br>
> This was actually one of my reservations about the proposed <br>
> microversioning implementation -- i.e. having functions that are<br>
> named exactly the same, only decorated with the microversioning<br>
> notation. It kinda reminds me of the hell of debugging C++ code that<br>
> uses STL: how does one easily know which method one is in when inside<br>
> a debugger?<br>
> <br>
> That said, the only other technique we could try to use would be to<br>
> not use a decorator and instead have a top-level dispatch function<br>
> that would inspect the API microversion (only when the API version<br>
> makes a difference to the output or input of that function) and then<br>
> dispatch the call to a helper method that had the version in its name.<br>
> <br>
> So, for instance, let's say you are calling the controller's GET <br>
> /$tenant/os-hosts method, which happens to get routed to the <br>
> nova.api.openstack.compute.contrib.hosts.HostController.index()<br>
> method. If you wanted to modify the result of that method and the API <br>
> microversion is at 2.5, you might do something like:<br>
> <br>
>   def index(self, req):<br>
>       req_api_ver = utils.get_max_requested_api_version(req)<br>
>       if req_api_ver == (2, 5):<br>
>           return self.index_2_5(req)<br>
>       return self.index_2_1(req)<br>
> <br>
>   def index_2_5(self, req):<br>
>       results = self.index_2_1(req)<br>
>       # Replaces 'host' with 'host_name'<br>
>       for result in results:<br>
>           result['host_name'] = result['host']<br>
>           del result['host']<br>
>       return results<br>
> <br>
>   def index_2_1(self, req):<br>
>       # Would be a rename of the existing index() method on<br>
>       # the controller....<br>
> <br>
<br>
So having to manually add switching code everything we have an API<br>
patch I think is not only longer and more complicated but more error<br>
prone when updating. If we change something at the core in the future it<br>
means changing all the microversioned code rather than just the<br>
switching architecture at the core of wsgi.<br>
<br>
<br>
> Another option would be to use something like JSON-patch to determine <br>
> the difference between two output schemas and automatically translate <br>
> one to another... but that would be a huge effort.<br>
> <br>
> That's the only other way I can think of besides disabling F811,<br>
> which I really would not recommend, since it's a valuable safeguard<br>
> against duplicate function names (especially duplicated test methods).<br>
<br>
So I don't think we need to disable F811 in general - why not just<br>
disable it for any method with the api_version decorator? On those ones<br>
we can do checks on what is passed to api_version which will help<br>
verify that there hasn't been a typo to an api_version decorator.<br>
<br>
Chris<br>
<br>
__________________________________________________________________________<br>
OpenStack Development Mailing List (not for usage questions)<br>
Unsubscribe: OpenStack-dev-request@lists.openstack.org?subject:unsubscribe<br>
</font></tt><tt><font size="2"><a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev">http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev</a></font></tt><tt><font size="2"><br>
<br>
</font></tt><br>
</body></html>