title: Infer a Python function definition statement by performing a static analysis on its body
body: <p>I am working in <a href="https://github.com/conala-corpus/conala-corpus.github.io" rel="nofollow noreferrer">CoNaLa dataset</a> contains high-quality natural language intent and source code snippet pairs in Python. The data are stored in JSON format, and you can see some examples below:</p>
  
  <pre><code>{
    "example": 1,
    "intent": "copying one file's contents to another in python", 
    "snippet": "shutil.copy(source_file, target_file)", 
  },
  
  {
    "example": 2
    "intent": "How do I check if all elements in a list are the same?", 
    "snippet": "len(set(mylist)) == 1", 
  }
  
  {
    "example": 3
    "intent": "Iterate through words of a file in Python", 
    "snippet": "words = open(my_file).read().split()"
  }
  
  </code></pre>
  
  <p>I am looking for an approach to encapsulate each of the code snippets into a function. However to accomplish that I would have to infer which parameters this function should contain. In example 1, for instance, function declaration could be:</p>
  
  <pre><code>def function_name (source_file, target_file):
  </code></pre>
  
  <p>where <code>function_name</code> can be a generic name but the parameters should be <code>source_file</code> and <code>target_file</code> because they must be known in <code>shutil.copy</code> method.</p>
  
  <p>For examples 2 and 3 the expected result would be respectively:</p>
  
  <pre><code>def function_name (myList):
  </code></pre>
  
  <p>and</p>
  
  <pre><code>def function_name (my_file):
  </code></pre>