Hi Adarsh,
This won't be possible in general. These language generator functions are merely responsible for translating blocks of code to strings of Python code. They do *not* run any code. For example, consider a contrived example of blocks generating the following Python code:
def f(): return "abc" if input("(s)tring or (n)umber?")=="s" else 42
x = f()
print(x)
Blockly.Python.variables_set would be passed a reference to a function call block. The value of this code which would be stored in b, would then be set to the string "f()". Without running the code, it would be impossible to know whether f returns a string or a number as it depends on the user input.
However, you can determine the types of blocks with safety checks (ones that pop out when they are placed in spots that do not make sense) such as the `math_number` block. To get this information, you could use `a.outputConnection.getCheck()` which will return an Array of all specified compatible types such as ["Number"] for the block referred to by `a` or or null if no safety checks have been specified (See:
https://github.com/google/blockly/blob/master/core/connection.js#L595)
Please feel free to follow up with any additional questions.
Best,
Jason