473,414 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Re: Type feedback tool?

I think that rope has something like that; not really sure though.

On Mon, Oct 27, 2008 at 1:41 AM, <sk**@pobox.comwrote:
>
(Sorry for any repeated recommendations. I'm offline until Monday morning.
You may well see some of these suggestions in the meanwhile, but so far it
seems you've had no nibbles.)

MartinI'm wondering if there's a tool that can analyze a Python
Martinprogram while it runs, and generate a database with the types of
Martinarguments and return values for each function.

Nothing that I'm aware of. Here are a few ideas though.

1. Modify the source code in question to decorate any functions you're
interested in, e.g.:

#!/usr/bin/env python

class ZeroDict(dict):
def __getitem__(self, key):
if key not in self:
return 0
return dict.__getitem__(self, key)

_argtypes = ZeroDict()

def note_types(f):
"Decorator that keeps track of counts of arg types for various functions."
def _wrapper(*args):
_argtypes[(f,) + tuple([type(a) for a in args])] += 1
return f(*args)
return _wrapper

@note_types
def fib(n):
if n < 0:
raise ValueError, "n < 0"
if n 1:
return fib(n-1) + fib(n-2)
return 1

@note_types
def fib2(n):
"fib() that guarantees it is dealing with ints."
if n < 0:
raise ValueError, "n < 0"
n = int(n)
if n 1:
return fib2(n-1) + fib2(n-2)
return 1

if __name__ == "__main__":
print "fib(5) ==", fib(5)
print "fib(4.0) ==", fib(4.0)
print "fib2(5) ==", fib2(5)
print "fib2(4.0) ==", fib2(4.0)
print _argtypes

You can probably write a source transformation tool to decorate all
functions (or just use Emacs macros for a 99% solution which takes a lot
less time).

2. Look at tools like pdb. You might be able to add a new command to
decorate a function in much the same way that you might set a breakpoint
at a given function.

3. Take a look at IDEs with source (like IDLE). You might be able to coax
them into decorating functions then display the collected statistics when
you view the source (maybe display a tooltip with the stats for a
particular function).

Skip
--
http://mail.python.org/mailman/listinfo/python-list


--
or*****@orestis.gr
http://orestis.gr
Oct 27 '08 #1
0 1002

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alan Shi [MSFT] | last post by:
I am collecting data for two features that shipped with the CLR in v1.0 and v1.1. If you use and/or depend on these features, I would appreciate hearing from you with a brief description of how you...
1
by: Bill Menees | last post by:
VS.NET 2003 defaults the "Debugger Type" property to "Auto" for Visual C++ projects. Unfortunately, the "Auto" type isn't very smart. "Auto" bases the debugger type on the launched EXE's type,...
0
by: hlyall1189 | last post by:
Hi, I recently started upgrading some of my old vs 2003 apps to vs 2005 and used the conversion tool but now i get the following error after building the page. I have typecasted the lines as...
7
by: Sky | last post by:
I have been looking for a more powerful version of GetType(string) that will find the Type no matter what, and will work even if only supplied "{TypeName}", not the full "{TypeName},{AssemblyName}"...
2
by: blangela | last post by:
I have put together a 7 page (in Word) doc which introduces the topic of deep copy versus shallow copy and associated topics for my introductory C++ class. The topic does not go into too much...
0
by: bji-ggcpp | last post by:
Xrtti is a tool and accompanying C++ library which extends the standard runtime type system of C++ to provide a much richer set of reflection information about classes and methods to manipulate...
5
by: Max2006 | last post by:
Hi, When I want to specify a type \in web.config or app.config files, I have to type it like this: type="Microsoft.WCF.Documentation.EnforceGreetingFaultBehavior, HostApplication,...
8
by: =?Utf-8?B?ZG1idXNv?= | last post by:
I'm migrating a VB.NET 2003 application to VB.NET 2008. The 2003 app used the June 2005 Enterprise Library while I'm going to use the latest EntLib, 4.0 - May 2008. I copied the 2003 app to a...
1
by: Martin Vilcans | last post by:
Hi list, I'm wondering if there's a tool that can analyze a Python program while it runs, and generate a database with the types of arguments and return values for each function. In a way it is...
0
by: Martin Vilcans | last post by:
Thanks everyone for the suggestions. I've implemented a simple solution using sys.settrace. It's quite nice because it doesn't require any instrumentation of the code (it works like a debugger that...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.