Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement formatting for MappingProxyView.info #30

Merged
merged 2 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/einspect/structs/mapping_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

from einspect.structs.deco import struct
from einspect.structs.py_dict import PyDictObject
from einspect.structs.py_object import PyObject
from einspect.structs.py_object import Fields, PyObject
from einspect.types import ptr

__all__ = ("MappingProxyObject",)


_KT = TypeVar("_KT")
_VT_co = TypeVar("_VT_co", covariant=True)

Expand All @@ -21,7 +23,13 @@ class MappingProxyObject(PyObject[MappingProxyType, _KT, _VT_co]):
https://github.com/python/cpython/blob/3.11/Objects/descrobject.c#L1027-L1030
"""

mapping: PyDictObject[_KT, _VT_co]
mapping: ptr[PyDictObject[_KT, _VT_co]]

def _format_fields_(self) -> Fields:
return {
**super()._format_fields_(),
"mapping": "*PyDictObject",
}

@classmethod
def from_object(
Expand Down
3 changes: 1 addition & 2 deletions src/einspect/views/view_mapping_proxy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

from ctypes import pointer
from types import MappingProxyType
from typing import TypeVar

Expand Down Expand Up @@ -47,4 +46,4 @@ def mapping(self) -> dict[_KT, _VT]:
@mapping.setter
@unsafe
def mapping(self, value: dict[_KT, _VT]) -> None:
self._pyobject.mapping = pointer(PyDictObject.from_object(value))
self._pyobject.mapping = PyDictObject.from_object(value).with_ref().as_ref()