@@ -635,11 +635,42 @@ class DictSubtype(dict): ...
635635 self .assertIs (type (d ), DictSubtype )
636636 self .assertEqual (d , DictSubtype ({}))
637637
638+ # non str keys:
639+ d = {1 : 'a' , 2 : 'b' , 3 : 'c' , None : 'f' }
640+ f = as_frozendict (d )
641+ self .assertIs (type (f ), frozendict )
642+ self .assertEqual (f , frozendict ({1 : 'a' , 2 : 'b' , 3 : 'c' , None : 'f' }))
643+ self .assertIs (type (d ), dict )
644+ self .assertEqual (d , {})
645+
646+ d = DictSubtype ({1 : 'a' , 2 : 'b' , 3 : 'c' , None : 'f' })
647+ f = as_frozendict (d )
648+ self .assertIs (type (f ), frozendict )
649+ self .assertEqual (f , frozendict ({1 : 'a' , 2 : 'b' , 3 : 'c' , None : 'f' }))
650+ self .assertIs (type (d ), DictSubtype )
651+ self .assertEqual (d , DictSubtype ({}))
652+
653+ # wrong inputs:
638654 for wrong_input in (frozendict (), [], None ):
639655 with self .subTest (wrong_input = wrong_input ):
640656 with self .assertRaises (SystemError ):
641657 as_frozendict (wrong_input )
642658
659+ # gh-161767: check embedded values
660+ class Regular : ...
661+
662+ for klass in (Regular , _testcapi .ManagedDictType ):
663+ with self .subTest (klass = klass ):
664+ instance = klass ()
665+ instance .key = 'value'
666+ with self .assertRaisesRegex (ValueError , 'embedded values' ):
667+ as_frozendict (instance .__dict__ )
668+
669+ self .assertEqual (instance .__dict__ , {'key' : 'value' })
670+ # Both of these actions were needed to cause a crash:
671+ instance .other = 'new'
672+ del instance # must not crash
673+
643674 def test_frozendict_check (self ):
644675 # Test PyFrozenDict_Check()
645676 check = _testcapi .frozendict_check
0 commit comments