File: foxdot_func_cmp.py

package info (click to toggle)
python-renardo-lib 0.9.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,220 kB
  • sloc: python: 10,999; sh: 34; makefile: 7
file content (27 lines) | stat: -rw-r--r-- 692 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""
    compare_functions.py(funcA, funcB):

        returns True if the functions are identical
    
"""

def func_cmp(funcA, funcB):

    codeA = funcA.__code__
    A_bytecode  = codeA.co_code
    A_constants = codeA.co_consts
    A_variables = codeA.co_names

    codeB = funcB.__code__
    B_bytecode  = codeB.co_code
    B_constants = codeB.co_consts
    B_variables = codeB.co_names
    
    return all([A_bytecode == B_bytecode,
                A_constants == B_constants,
                A_variables == B_variables])

def func_str(func):
    """ Returns a function as a string """
    code = func.__code__
    return ",".join([func.__name__, str(code.co_names), str(code.co_consts)])