Skip to content

Expose class to get_tag hook#857

Open
dprbook wants to merge 2 commits intojcrist:mainfrom
dprbook:main
Open

Expose class to get_tag hook#857
dprbook wants to merge 2 commits intojcrist:mainfrom
dprbook:main

Conversation

@dprbook
Copy link

@dprbook dprbook commented Jun 18, 2025

I had a use case, where I needed the fully qualified name of the class in the get_tag hook.
This change calls the hook function with the class as second, optional param, making this change non-breaking.

Alternatively, the second param could be the module path, but this is more flexible.

Usage

from msgspec import Struct def get_tag(qualname, cls): # This still uses the qualname extraction in simple_qualname, see: # https://github.com/jcrist/msgspec/blob/bb5bc8dc75509ec6a2e6e0f0b3359028e584c651/msgspec/_core.c#L6060 return f"{cls.__module__}.{qualname}" # or def get_tag(_, cls): # Native Python behavior return f"{cls.__module__}.{cls.__qualname__}" # still works def get_tag(qualname): return qualname class S(Struct, tag=get_tag): a: int = 1

Any feedback welcome. Nice lib :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant