diff --git a/LICENSE b/LICENSE index 6344378f1bfc3508dde3f622d477fed654880ccb..38e365b62b7a8efb3fef9c976833dbb420fd9132 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2013-2021 Piotr MaĹlanka +Copyright (c) 2013-2023 Piotr MaĹlanka Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/docs/conf.py b/docs/conf.py index d8ec47dc221963ba2918c45daeb53bb70233db04..825151a617b5a9d18d96ee9edeb88369eaafcbaf 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -49,7 +49,7 @@ master_doc = 'index' # General information about the project. project = u'satella' -copyright = u'2017-2020, Piotr MaĹlanka' +copyright = u'2017-2022, Piotr MaĹlanka' author = u'Piotr MaĹlanka' # The version info for the project you're documenting, acts as replacement for diff --git a/satella/coding/overloading.py b/satella/coding/overloading.py index c4f1c0eb46dcc79e365ff58692a2e76e7234e9c7..4b4d98a9fea0175a3a320a5a8b424f76d149e87b 100644 --- a/satella/coding/overloading.py +++ b/satella/coding/overloading.py @@ -106,6 +106,7 @@ class overload: if hasattr(fun, '__doc__'): self.__doc__ = fun.__doc__ self.__wrapped__ = fun + self.history_list = [] def overload(self, fun): """ @@ -113,7 +114,7 @@ class overload: """ sign = TypeSignature.from_fun(fun) if sign in self.type_signatures_to_functions: - raise TypeError('Method of this signature is already overloaded with %s' % (f,)) + raise TypeError('Method of this signature is already overloaded with %s' % (fun,)) self.type_signatures_to_functions[sign] = fun return self @@ -123,12 +124,16 @@ class overload: :raises TypeError: no type signature given """ - matching = [] + matchings = [] for sign, fun in self.type_signatures_to_functions.items(): + print('Matching %s against %s', sign, fun) if sign.matches(*args, **kwargs): - matching.append((sign, fun)) - matching.sort() - if not matching: + matchings.append((sign, fun)) + else: + print('Did not score a math between %s:%s and %s', args, kwargs, ) + matchings.sort() + print(matchings) + if not matchings: raise TypeError('No matching entries!') else: - return matching[-1][1](*args, **kwargs) # call the most specific function you could find + return matchings[-1][1](*args, **kwargs) # call the most specific function you could find diff --git a/tests/test_coding/test_misc.py b/tests/test_coding/test_misc.py index a993844debcf873014a36d50d578b95a00032ec3..f070a933cfeb994314fbd90a62fa8d2743e621fb 100644 --- a/tests/test_coding/test_misc.py +++ b/tests/test_coding/test_misc.py @@ -228,15 +228,20 @@ class TestCase(unittest.TestCase): def what_type(x): a['type'] = 'any' + @what_type.overload + def what_type(x: (int, float)): + a['type'] = 'num' + what_type('test') self.assertEqual(a['type'], 'str') what_type(2) self.assertEqual(a['type'], 'int') - what_type(None) - self.assertEqual(a['type'], 'any') what_type(2.0) + self.assertEqual(a['type'], 'num') + what_type(None) self.assertEqual(a['type'], 'any') + def test_update_key_if_not_none(self): a = {} update_key_if_not_none(a, 'test', None)