how to deal with deprecating API functionality in python module?

2013-11-20 Thread Chris Friesen

Hi,

I'm pretty new to python, I'm trying to figure out how a python module 
is supposed to make non-backwards-compatible changes without blowing up 
the applications that use it.


In the C world this is straightforward, an application is linked against 
version X of the library, and if the library developers make a 
non-compatible change (remove a deprecated function, or change a 
function signature) they bump the version to X+1.  Then versions X and 
X+1 can both be installed on the system at the same time and 
applications will link against whichever one they were compiled against.


How would something like this work in a python application?  I don't see 
any way to do the equivalent of


import foo version X


Is the only way to incorporate the version in the name?  Like:

import fooX


Any guidance would be appreciated...


Thanks,
Chris
--
https://mail.python.org/mailman/listinfo/python-list


python IDE and function definition

2013-09-23 Thread Chris Friesen


Hi all,

I'm looking for a python IDE (for Linux) that can look at code like this:

class ConductorManager(manager.Manager):
def compute_recover(self, context, instance):
self.compute_api.stop(context, instance, do_cast=False)

where I could highlight the "stop" and ask it to go to the definition. 
(Where the definition is in a different file.)


I'm running into issues where my current IDE (I'm playing with Komodo) 
can't seem to locate the definition, I suspect because it's too ambiguous.


The fact that python is dynamically typed seems to mean that there could 
potentially be multiple answers, any class with a stop() method with the 
right signature could presumably be plausible, right?  So rather than 
give up, I'd like to have my IDE suggest all possible answers.


Chris
--
https://mail.python.org/mailman/listinfo/python-list


Re: python IDE and function definition

2013-09-23 Thread Chris Friesen

On 09/23/2013 09:32 AM, Fabio Zadrozny wrote:

On Mon, Sep 23, 2013 at 12:06 PM, Chris Friesen mailto:cbf...@mail.usask.ca>> wrote:


Hi all,

I'm looking for a python IDE (for Linux) that can look at code like
this:

class ConductorManager(manager.__Manager):
 def compute_recover(self, context, instance):
 self.compute_api.stop(context, instance, do_cast=False)

where I could highlight the "stop" and ask it to go to the
definition. (Where the definition is in a different file.)

I'm running into issues where my current IDE (I'm playing with
Komodo) can't seem to locate the definition, I suspect because it's
too ambiguous.

The fact that python is dynamically typed seems to mean that there
could potentially be multiple answers, any class with a stop()
method with the right signature could presumably be plausible,
right?  So rather than give up, I'd like to have my IDE suggest all
possible answers.



PyDev (http://pydev.org/) is able to do that (i.e.: if the find
definition doesn't find it directly, it shows a list with possible
matches for you to choose the most appropriate one:
http://pydev.org/manual_adv_gotodef.html) -- additionally, you can also
search for methods/classes/attributes directly:
http://pydev.org/manual_adv_open_decl_quick.html


I've installed eclipse/pydev and tried it out.  The problem that I'm 
seeing is that it will show me *all* stop() methods that it knows about, 
regardless of function signature.


So in the above case, my function call looks like:
self.compute_api.stop(context, instance, do_cast=False)

but pydev will offer matches that look like:
def stop(self):

This runs into problems with commonly-named functions.  I tried 
searching for the start() method in:


self.compute_api.start(context, instance)

and it complained that there were too many possible results.

Basically, I'm looking for something smart enough to throw out methods 
with the same name but that don't match the signature.


Chris

--
https://mail.python.org/mailman/listinfo/python-list


python function parameters, debugging, comments, etc.

2013-10-01 Thread Chris Friesen

I've got a fair bit of programming experience (mostly kernel/POSIX stuff in C). 
 I'm fairly new to python though, and was hoping for some advice.

Given the fact that function parameters do not specify types, when you're 
looking at someone else's code how the heck do you know what is expected for a 
given argument?  (Especially in a nontrivial system where the parameter is just 
passed on to some other function and may not be evaluated for several nested 
function calls.)

Is the recommendation to have comments for each function describing the 
expected args?

I was trying to debug some stuff that someone else wrote.  It turned out that 
the problem was in code like this:



def rebuild_instance(self, context, instance, image, ...)
request_spec = scheduler_utils.build_request_spec(context, image, 
[instance])
...stuff...
other_function(...,image,...)


where build_request_spec looks like:

def build_request_spec(ctxt, image, instances):
...etc...


and it took me a while to realize that rebuild_instance() was being passed the 
image ID (basically just a string), and other_function() was expecting the 
image ID, but build_request_spec() was expecting the actual image dictionary.

It also took me a while to realize that that build_request_spec() was expecting 
a list of instances, while rebuild_instance() was passing in a single instance. 
 That one is already fixed in the above code.


So what's the recommended way of dealing with stuff like this in larger 
projects with many developers?

Thanks,
Chris
-- 
https://mail.python.org/mailman/listinfo/python-list