diff options
author | Dmitry Pribysh <dmand@yandex.ru> | 2015-10-18 18:38:06 +0300 |
---|---|---|
committer | Dmitry Pribysh <dmand@yandex.ru> | 2015-10-18 18:38:06 +0300 |
commit | b12c2803500c0b883b3a12b4cfc0b174ac52c4f8 (patch) | |
tree | cec7e8070513571385aefff8c0a8c8fecd449710 /pylint/test/functional/mapping_context.py | |
parent | 5c8335754a164bc8073bc8623a887894fe4e8c24 (diff) | |
parent | 6c6ec4a713118136ccdd9117693078e15fcccbbe (diff) | |
download | pylint-iterable-checker.tar.gz |
Merge with defaultiterable-checker
Diffstat (limited to 'pylint/test/functional/mapping_context.py')
-rw-r--r-- | pylint/test/functional/mapping_context.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/pylint/test/functional/mapping_context.py b/pylint/test/functional/mapping_context.py new file mode 100644 index 0000000..cfab8dc --- /dev/null +++ b/pylint/test/functional/mapping_context.py @@ -0,0 +1,59 @@ +""" +Checks that only valid values are used in a mapping context. +""" +# pylint: disable=missing-docstring,invalid-name,too-few-public-methods,no-self-use,import-error +from __future__ import print_function + + +def test(**kwargs): + print(kwargs) + + +# dictionary value/comprehension +dict_value = dict(a=1, b=2, c=3) +dict_comp = {chr(x): x for x in range(256)} +test(**dict_value) +test(**dict_comp) + + +# in order to be used in kwargs custom mapping class should define +# __iter__(), __getitem__(key) and keys(). +class CustomMapping(object): + def __init__(self): + self.data = dict(a=1, b=2, c=3, d=4, e=5) + + def __getitem__(self, key): + return self.data[key] + + def keys(self): + return self.data.keys() + +test(**CustomMapping()) +test(**CustomMapping) # [not-a-mapping] + +class NotMapping(object): + pass + +test(**NotMapping()) # [not-a-mapping] + +# skip checks if statement is inside mixin class +class SomeMixin(object): + kwargs = None + + def get_kwargs(self): + return self.kwargs + + def run(self, **kwargs): + print(kwargs) + + def dispatch(self): + kws = self.get_kwargs() + self.run(**kws) + +# skip uninferable instances +from some_missing_module import Mapping + +class MyClass(Mapping): + pass + +test(**MyClass()) |