1

I would like to use a literate programming tool to write a python program. My tool of choice is noweb. My IDE is emacs.

The problem I have is that I have classes with identical method names. For example, the python program implements web service clients to several web service servers, each of which has a search service. At first glance I would code this as follows:

class wsca:
    def search(self, client, searchInput):
        pass

class wscb:
    def search(self, client, searchInput):
        pass

The results of weaving this show that search is defined twice, and it is not possible to see where in the code wsca.search() is called and where wscb.search() is called.

To solve this, one option I can think of is to give the methods unique names, but I do not see this as an acceptable solution.

Does anyone have a solution to this problem?

Finwood
  • 3,829
  • 1
  • 19
  • 36
  • Create a parent class with one copy of `search` in it, and inherit from that. If the two `search` methods are different, then why should that be a problem? – cdarke Jul 08 '15 at 08:41
  • The name of a method includes its class, so `wsca.search` and `wscb.search` are the names of two distinct methods — so there should be no problem. – martineau Jul 08 '15 at 10:28
  • @cdarke - Thank you for your comment. The issue I am having is in the indices generated by noweb. These show where a function call is defined and used. As you can imagine, with many methods named search, these indices become less useful, since there no distinction can be made between the different search methods. – Adnan Yaqub Jul 09 '15 at 10:30
  • @martineau - Thank you for your comment. I have two issues. First when noweb sees 'wsca.search' it marks this as a call to 'search' in the indices. Second, the name 'wsca' will change depending on the python coding, since the name of the object instance can be freely chosen. – Adnan Yaqub Jul 09 '15 at 10:39
  • noweb may never see a `wsca.search` reference unless the code refers to the class method as opposed to an instance's method. `wsca` and `wscb` are the names of classes, not instances of them. One typically creates class instances after it is defined by calling the class. i.e. `inst_name = wsca()`. The method could then be called with `inst_name.search(args...)` where `inst_name` can be any valid identifier name. To know which `search()` is being called requires knowing the type of the `inst_name` object, which in this example is `wsca`, so the method actually being called is `waca.search`. – martineau Jul 09 '15 at 13:44

0 Answers0