Tools to help developers reading class hierarchy faster

2024/9/30 1:31:56

I mostly spend time on Python/Django and Objective-C/CocoaTouch and js/jQuery in the course of my daily work.

My editor of choice is vim for Python/Django and js/jQuery and xcode for Objective-C/CocoaTouch.

One of the bottlenecks on my development speed is the pace at which I read existing code, particularly open source libraries which I use.

In Python/Django for example, when I encounter some new features introduced by django developers, I get curious and begin exploring the code base manually. For example, when class-based views were introduced from django 1.3 onwards, reference - https://docs.djangoproject.com/en/dev/topics/class-based-views/ - I will check out the example code shown:

from django.views.generic import TemplateViewclass AboutView(TemplateView):template_name = "about.html"

And try it out on one of my projects. More importantly, I am curious about what goes on behind the scenes, so I will dig into the source code -

# django/views/generic/__init__.py filefrom django.views.generic.base import View, TemplateView, RedirectView
from django.views.generic.dates import (ArchiveIndexView, YearArchiveView, MonthArchiveView,WeekArchiveView, DayArchiveView, TodayArchiveView,DateDetailView)
from django.views.generic.detail import DetailView
from django.views.generic.edit import FormView, CreateView, UpdateView, DeleteView
from django.views.generic.list import ListViewclass GenericViewError(Exception):"""A problem in a generic view."""pass

From here, I will trace it backwards to the django/views/generic/base.py file and find out exactly what TemplateView class does:-

class TemplateView(TemplateResponseMixin, View):"""A view that renders a template."""def get_context_data(self, **kwargs):return {'params': kwargs}def get(self, request, *args, **kwargs):context = self.get_context_data(**kwargs)return self.render_to_response(context)

And here's it shows that TemplateView class inherits from TemplateResponseMixin and View classes... and I continue digging further... and so on...

The problem is, this is an extremely inefficient and slow process (to "follow" class hierachies manually and opening up each file along the way).

So the question is - is there an easy way/UI tool (or other visual solution) that parses Python code in a particular project and visualize class hierarchies which I can then inspect easily by "clicking" on a specific class I am interested to read about?

Note that I am aware of IPython shell but that doesn't seem as user-friendly as a visual display tool.

For example, there's F-Script in the world of Objective-C/iOS/Mac programming, which not only provides a shell (much like python or IPython shell), but provides a visual way for developers to introspect class hierachies.

Reference screenshot:-

enter image description here

So is there a class-hierarchy visualization tool (for Python specifically, but even better if it's generic and can be used for different languages)??? What are your methods of getting up to speed efficiently when reading open source source code???

UPDATED

Per advice below, I tried out ctags and vim plugin taglist and I was able to use :TlistOpen to open up a side buffer in vim like this:-

enter image description here

This looks really cool as :TlistOpen now essentially shows me all the classes and functions that are available on my currently open buffer.

My problem now is that when I attempt to do Ctrl] while my cursor is on TemplateView, I get the following error:-

enter image description here

What am I doing wrong? Is it because my django source code is in a virtualenv? Or is there something specific I have to do to make ctags/taglist "aware" of the django source code?

Answer

Tags are a very good start indeed. (There's too much stuff all over the place on it, so I'll just provide you with one extra keyword to search with: ctags.)

In Vim, it ends up (in the basic case) with Ctrl+] to go to a class/function definition and Ctrl+T to return.

https://en.xdnf.cn/q/71145.html

Related Q&A

Python Last Iteration in For Loop [duplicate]

This question already has answers here:What is the pythonic way to detect the last element in a for loop?(34 answers)How do I read and write CSV files?(7 answers)Closed 9 months ago.Is there any simp…

Django 1.7 multisite User model

I want to serve a Django application that serves multiple web sites by single database but different user sets. Think like a blog application, it will be used by several domains with different themes, …

Does for key in dict in python always iterate in a fixed order?

Does the python codefor key in dict:..., where dict is a dict data type, always iterate in a fixed order with regrard to key? For example, suppose dict={"aaa":1,"bbb",2}, will the …

Kinesis Firehose lambda transformation

I have the following lambda function as part of Kinesis firehose record transformation which transforms msgpack record from the kinesis input stream to json.Lambda Runtime: python 3.6from __future__ im…

Python: find out whether a list of integers is coherent

I am trying to find out whether a list of integers is coherent or at one stretch, meaning that the difference between two neighboring elements must be exactly one and that the numbers must be increasin…

Create resizable/multiline Tkinter/ttk Labels with word wrap

Is it possible to create a multi-line label with word wrap that resizes in sync with the width of its parent? In other words the wordwrap behavior of Notepad as you change the width of the NotePad win…

Unicode, regular expressions and PyPy

I wrote a program to add (limited) unicode support to Python regexes, and while its working fine on CPython 2.5.2 its not working on PyPy (1.5.0-alpha0 1.8.0, implementing Python 2.7.1 2.7.2), both run…

Python str object has no attribute read

Python 3.3.2 import json & urllib.requestJson[{"link":"www.google.com","orderid":"100000222"}, {"link":"www.google.com","orderid&quo…

Efficient upsert of pandas dataframe to MS SQL Server using pyodbc

Im trying to upsert a pandas dataframe to a MS SQL Server using pyodbc. Ive used a similar approach before to do straight inserts, but the solution Ive tried this time is incredibly slow. Is there a mo…

Comparison on the basis of min function

How exactly does the min function work for lists in python ?For example,num = [1,2,3,4,[1,2,3]]num2 = [1,2,3,4,5]min(num,num2) gives num2 as the result. Is the comparison value based or length based ?