Skip to content

Instantly share code, notes, and snippets.

@tdwiser
Created September 24, 2024 16:55
Show Gist options
  • Save tdwiser/753b353b457c45faf2cefbfcf4bf23b7 to your computer and use it in GitHub Desktop.
Save tdwiser/753b353b457c45faf2cefbfcf4bf23b7 to your computer and use it in GitHub Desktop.
from __future__ import annotations
from dataclasses import dataclass
@dataclass(frozen=True)
class DocKey:
key: str
__doc__: str
def __repr__(self):
return repr(self.key)
def __hash__(self):
return hash(self.key)
def __eq__(self, value):
return self.key == value
sample_dict = {"key_a": 1, "key_b": 2}
doc_keys = [DocKey("key_a", "this is key A"), DocKey("key_b", "this is key B")]
for key in doc_keys:
print(f"{key=}, {key.__doc__=}, {sample_dict[key]=}")
help(doc_keys[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment