@@ -326,6 +326,16 @@ def _register_asn1_sequence(cls: type[U]) -> None:
326326 setattr (cls , "__asn1_root__" , root )
327327
328328
329+ def _register_asn1_set (cls : type [U ]) -> None :
330+ raw_fields = get_type_hints (cls , include_extras = True )
331+ root = declarative_asn1 .AnnotatedType (
332+ declarative_asn1 .Type .Set (cls , _annotate_fields (raw_fields )),
333+ declarative_asn1 .Annotation (),
334+ )
335+
336+ setattr (cls , "__asn1_root__" , root )
337+
338+
329339# Due to https://github.com/python/mypy/issues/19731, we can't define an alias
330340# for `dataclass_transform` that conditionally points to `typing` or
331341# `typing_extensions` depending on the Python version (like we do for
@@ -357,6 +367,29 @@ def sequence(cls: type[U]) -> type[U]:
357367 _register_asn1_sequence (dataclass_cls )
358368 return dataclass_cls
359369
370+ @typing_extensions .dataclass_transform (kw_only_default = True )
371+ def set (cls : type [U ]) -> type [U ]:
372+ # We use `dataclasses.dataclass` to add an __init__ method
373+ # to the class with keyword-only parameters.
374+ if sys .version_info >= (3 , 10 ):
375+ dataclass_cls = dataclasses .dataclass (
376+ repr = False ,
377+ eq = False ,
378+ # `match_args` was added in Python 3.10 and defaults
379+ # to True
380+ match_args = False ,
381+ # `kw_only` was added in Python 3.10 and defaults to
382+ # False
383+ kw_only = True ,
384+ )(cls )
385+ else :
386+ dataclass_cls = dataclasses .dataclass (
387+ repr = False ,
388+ eq = False ,
389+ )(cls )
390+ _register_asn1_set (dataclass_cls )
391+ return dataclass_cls
392+
360393else :
361394
362395 @typing .dataclass_transform (kw_only_default = True )
@@ -372,6 +405,19 @@ def sequence(cls: type[U]) -> type[U]:
372405 _register_asn1_sequence (dataclass_cls )
373406 return dataclass_cls
374407
408+ @typing .dataclass_transform (kw_only_default = True )
409+ def set (cls : type [U ]) -> type [U ]:
410+ # Only add an __init__ method, with keyword-only
411+ # parameters.
412+ dataclass_cls = dataclasses .dataclass (
413+ repr = False ,
414+ eq = False ,
415+ match_args = False ,
416+ kw_only = True ,
417+ )(cls )
418+ _register_asn1_set (dataclass_cls )
419+ return dataclass_cls
420+
375421
376422# TODO: replace with `Default[U]` once the min Python version is >= 3.12
377423@dataclasses .dataclass (frozen = True )
0 commit comments