# How to annotate a dict containing classes

**URL:** <https://discuss.python.org/t/how-to-annotate-a-dict-containing-classes/109279>\
**Category:** Python Help\
**Tags:** typing\
**Created:** [September 29, 2026, 11:30pm UTC](https://discuss.python.org/t/how-to-annotate-a-dict-containing-classes/109279 "2026-09-29T23:30:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![NickC](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/nickc/32/37293_2.png) [@NickC](https://discuss.python.org/u/NickC)\
**Post date:** [September 29, 2026, 11:30pm UTC](https://discuss.python.org/t/how-to-annotate-a-dict-containing-classes/109279/1 "2026-09-29T23:30:14Z")

</div>

How do I correctly annotate a dict containing a list of str and a class:

```python
local_dict: dict[(str, Any)] = {"oRequest": Process.oRequest, "oResponse": self}

```

Both oRequest and self are ~~classes~~ instances of their respective classes (Request & Response).

---

<div class="post-metadata">

**Author:** ![jonathandung](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jonathandung/32/35459_2.png) [@jonathandung](https://discuss.python.org/u/jonathandung)\
**Post date:** [September 29, 2026, 11:38pm UTC](https://discuss.python.org/t/how-to-annotate-a-dict-containing-classes/109279/2 "2026-09-29T23:38:01Z")

</div>

Use a `TypedDict`.

In the unlikely scenario that `self` is a class (a type, don’t think that’s what you meant):

```python
from typing import TypedDict
class MyDict(TypedDict):
    oRequest: type[Process.oRequest]
    oResponse: type[self]

```

If you instead meant `self` was an instance of a class (call it `C`), replace `type[self]` with `C`. Similar for `Process.oRequest`.

Finally, you can annotate `local_dict` with type `MyDict`.
