5
5
"""
6
6
7
7
import tomllib
8
- from typing import Literal
8
+ from typing import Literal , get_args
9
9
10
10
from pydantic import BaseModel , TypeAdapter , field_validator
11
11
@@ -34,24 +34,17 @@ class Tag(BaseModel):
34
34
35
35
@field_validator ("value" , mode = "before" )
36
36
def _validate_value (cls , v ) -> AllowedTagType :
37
- allowed_tags = set (AllowedTagType . __args__ )
37
+ allowed_tags = set (get_args ( AllowedTagType ) )
38
38
if v not in allowed_tags :
39
- raise ValueError (f"Invalid tag: { self . value } . Allowed: { allowed_tags } " )
39
+ raise ValueError (f"Invalid tag: { v } . Allowed: { allowed_tags } " )
40
40
return v
41
41
42
42
@property
43
43
def title_case (self ) -> str :
44
44
return " " .join ([t .title () for t in self .value .split ("-" )])
45
45
46
- def __eq__ (self , other ):
47
- if isinstance (other , Tag ):
48
- return self .value == other .value
49
- if isinstance (other , str ):
50
- return self .value == other
51
- return NotImplemented
52
46
53
-
54
- ALLOWED_TAGS = [Tag (value = tag ) for tag in set (AllowedTagType .__args__ )]
47
+ ALLOWED_TAGS = [Tag (value = tag ) for tag in set (get_args (AllowedTagType ))]
55
48
56
49
57
50
class Plugin (BaseModel ):
@@ -73,6 +66,4 @@ def parse_plugins(metadata_text: str) -> list[Plugin]:
73
66
pyinfra_metadata = tomllib .loads (metadata_text ).get ("pyinfra" , None )
74
67
if not pyinfra_metadata :
75
68
raise ValueError ("Missing [pyinfra.plugins] section in pyinfra-metadata.toml" )
76
- return TypeAdapter (list [Plugin ]).validate_python (
77
- pyinfra_metadata ["plugins" ].values ()
78
- )
69
+ return TypeAdapter (list [Plugin ]).validate_python (pyinfra_metadata ["plugins" ].values ())
0 commit comments