2020from __future__ import annotations
2121
2222from pathlib import Path
23- from typing import Dict , Iterable , Iterator , List , Optional , Tuple , Union
23+ from typing import (
24+ Dict ,
25+ Iterable ,
26+ Iterator ,
27+ List ,
28+ Literal ,
29+ Optional ,
30+ Tuple ,
31+ Union ,
32+ )
2433from xml .etree .ElementTree import Element
2534from xml .etree .ElementTree import fromstring as etree_from_str
2635from xml .etree .ElementTree import parse as etree_from_file
@@ -402,20 +411,21 @@ def __repr__(self) -> str:
402411
403412
404413class DbusPropertyIntrospection (DbusMemberAbstract ):
405- _EMITS_CHANGED_MAP : Dict [ str , Optional [ str ]] = {
406- 'true' : 'DbusPropertyEmitsChangeFlag' ,
407- 'false' : None ,
408- 'invalidates' : 'DbusPropertyEmitsInvalidationFlag' ,
409- 'const' : 'DbusPropertyConstFlag' ,
410- }
414+ _EMITS_CHANGED_MAP : \
415+ Dict [ Union [ bool , None , Literal [ 'const' , 'invalidates' ]], str ] = {
416+ True : 'DbusPropertyEmitsChangeFlag' ,
417+ 'invalidates' : 'DbusPropertyEmitsInvalidationFlag' ,
418+ 'const' : 'DbusPropertyConstFlag' ,
419+ }
411420
412421 def __init__ (self , element : Element ):
413422 if element .tag != 'property' :
414423 raise ValueError (f"Expected property tag, got { element .tag } " )
415424
416425 self .dbus_signature = element .attrib ['type' ]
417426
418- self .emits_changed : Optional [str ] = None
427+ self .emits_changed : \
428+ Union [bool , Literal ['const' , 'invalidates' ], None ] = None
419429 self .is_explicit = False
420430
421431 access_type = element .attrib ['access' ]
@@ -429,8 +439,9 @@ def __init__(self, element: Element):
429439 super ().__init__ (element )
430440
431441 def _flags_iter (self ) -> Iterator [str ]:
432- if self .emits_changed is not None :
433- yield self .emits_changed
442+ emits_changed_str = self ._EMITS_CHANGED_MAP .get (self .emits_changed )
443+ if emits_changed_str is not None :
444+ yield emits_changed_str
434445
435446 yield from super ()._flags_iter ()
436447
@@ -440,11 +451,17 @@ def _parse_annotation_data(self,
440451
441452 if annotation_name == ('org.freedesktop.DBus.Property'
442453 '.EmitsChangedSignal' ):
443- if annotation_value not in self ._EMITS_CHANGED_MAP :
454+ if annotation_value == 'true' :
455+ self .emits_changed = True
456+ elif annotation_value == 'false' :
457+ self .emits_changed = False
458+ elif annotation_value == 'const' :
459+ self .emits_changed = 'const'
460+ elif annotation_value == 'invalidates' :
461+ self .emits_changed = 'invalidates'
462+ else :
444463 raise ValueError ('Unknown EmitsChanged value' ,
445464 annotation_value )
446-
447- self .emits_changed = self ._EMITS_CHANGED_MAP [annotation_value ]
448465 elif annotation_name == 'org.freedesktop.systemd1.Explicit' :
449466 self .is_explicit = parse_str_bool (annotation_value )
450467
0 commit comments