MCPcopy Index your code
hub / github.com/RustPython/RustPython / naive_dict_check

Method naive_dict_check

Lib/test/test_typing.py:4934–4943  ·  view source on GitHub ↗
(obj, tp)

Source from the content-addressed store, hash-verified

4932
4933 def test_naive_runtime_checks(self):
4934 def naive_dict_check(obj, tp):
4935 # Check if a dictionary conforms to Dict type
4936 if len(tp.__parameters__) > 0:
4937 raise NotImplementedError
4938 if tp.__args__:
4939 KT, VT = tp.__args__
4940 return all(
4941 isinstance(k, KT) and isinstance(v, VT)
4942 for k, v in obj.items()
4943 )
4944 self.assertTrue(naive_dict_check({'x': 1}, typing.Dict[str, int]))
4945 self.assertFalse(naive_dict_check({1: 'x'}, typing.Dict[str, int]))
4946 with self.assertRaises(NotImplementedError):

Callers

nothing calls this directly

Calls 4

lenFunction · 0.85
allFunction · 0.85
isinstanceFunction · 0.85
itemsMethod · 0.45

Tested by

no test coverage detected