Skip to content

Commit

Permalink
Verify ItemsView, KeysView, and ValuesView in immutable_types
Browse files Browse the repository at this point in the history
Summary: Implement `ItemsView`, `KeysView`, and `ValuesView` in immutable_types

Reviewed By: ahilger

Differential Revision: D67978114

fbshipit-source-id: c6cbaceff4296b8e2e93f05bed027a05e2d4919e
  • Loading branch information
Danfeng Wang authored and facebook-github-bot committed Jan 11, 2025
1 parent a5aadbb commit 16733b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 14 additions & 0 deletions thrift/lib/python/test/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import unittest

from collections.abc import ItemsView, KeysView, ValuesView

from enum import Enum
from typing import Dict, Type, TypeVar

Expand Down Expand Up @@ -174,6 +176,18 @@ def test_contains_enum(self) -> None:
self.assertIn(self.Color.blue, cmap.colorMap)
self.assertNotIn(self.Color.green, cmap.colorMap)

def test_dict_views(self) -> None:
dmap = self.StrStrMap({"test": "value"})
dmap_keys = dmap.keys()
dmap_values = dmap.values()
dmap_items = dmap.items()
self.assertEqual(len(dmap_keys), 1)
self.assertEqual(len(dmap_values), 1)
self.assertEqual(len(dmap_items), 1)
self.assertIsInstance(dmap_keys, KeysView)
self.assertIsInstance(dmap_values, ValuesView)
self.assertIsInstance(dmap_items, ItemsView)

def test_items_values(self) -> None:
x = {"test": "value"}
tx = self.StrStrMap(x)
Expand Down
1 change: 0 additions & 1 deletion thrift/lib/python/types.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2153,7 +2153,6 @@ cdef class Set(Container):

pySet.register(Set)


cdef class MapTypeFactory:
cdef object key_info
cdef object val_info
Expand Down

0 comments on commit 16733b1

Please sign in to comment.