Commits

Mikhail Korobov committed 8b285f7

Line number is added to cache key in order to properly generate cache keys for inner functions with same names

  • Participants
  • Parent commits ac8bbb2

Comments (0)

Files changed (2)

File cache_utils/tests.py

         self.assertEqual(info[1], args_out)
 
     def test_func(self):
-        self.assertFuncInfo(foo, [1,2], 'cache_utils.tests.foo', [1,2])
+        self.assertFuncInfo(foo, [1,2], 'cache_utils.tests.foo:9', [1,2])
 
     def test_method(self):
         foo_obj = Foo()
         self.assertFuncInfo(Foo.foo, [foo_obj, 1, 2],
-                            'cache_utils.tests.Foo.foo', [1,2])
+                            'cache_utils.tests.Foo.foo:13', [1,2])
 
     def test_classmethod(self):
         self.assertFuncInfo(Foo.bar, [Foo, 1],
-                            'cache_utils.tests.Foo.bar', [1])
+                            'cache_utils.tests.Foo.bar:15', [1])
 
 
 class SanitizeTest(TestCase):

File cache_utils/utils.py

     'cls' and 'self' removed from normalized_args '''
 
     func_type = _func_type(func)
+    lineno = ":%s" % func.__code__.co_firstlineno
 
     if func_type == 'function':
-        return ".".join([func.__module__, func.__name__]), args
+        name = ".".join([func.__module__, func.__name__]) + lineno
+        return name, args
 
     class_name = args[0].__class__.__name__
     if func_type == 'classmethod':
         class_name = args[0].__name__
 
-    return ".".join([func.__module__, class_name, func.__name__]), args[1:]
+    name = ".".join([func.__module__, class_name, func.__name__]) + lineno
+    return name, args[1:]
 
 
 def _cache_key(func_name, func_type, args, kwargs):