473,324 Members | 2,179 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,324 software developers and data experts.

Type feedback tool?

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 like a profiler, that
instead of measuring how often functions are called and how long time
it takes, it records the type information. So afterwards, when I'm
reading the code, I can go to the database to see what data type
parameter "foo" of function "bar" typically has. It would help a lot
with deciphering old code.

When I googled this, I learned that this is called "type feedback",
and is used (?) to give type information to a compiler to help it
generate fast code. My needs are much more humble. I just want a
faster way to understand undocumented code with bad naming.

--
ma****@librador.com
http://www.librador.com
Oct 26 '08 #1
1 1051
Martin Vilcans wrote:
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 like a profiler, that
instead of measuring how often functions are called and how long time
it takes, it records the type information. So afterwards, when I'm
reading the code, I can go to the database to see what data type
parameter "foo" of function "bar" typically has. It would help a lot
with deciphering old code.

When I googled this, I learned that this is called "type feedback",
and is used (?) to give type information to a compiler to help it
generate fast code. My needs are much more humble. I just want a
faster way to understand undocumented code with bad naming.
It should be pretty easy to do this as a decorator, then (perhaps
automatically) sprinkle it around your source.

def watch(function):
def wrapped(*args, **kwargs):
argv = map(type, args)
argd = dict((key, type(value)) for key, value
in kwargs.iteritems())
try:
result = function(*args, **kwargs)
except Exception, exc:
record_exception(function, type(exc), argv, argd)
raise
else:
record_result(function, type(result), argv, argd)
return wrapped

then fill your normal code with:

@watch
def somefun(arg, defarg=1):
...
...
Finally record_* could write to a data structure (using bits like
function.__name__, and f.__module__, and possibly goodies from inspect).
Then you wrap your actual code start with something like:

try:
main(...)
finally:
<write data structure to DB>
--Scott David Daniels
Sc***********@Acm.Org
Oct 26 '08 #2

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...
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.