11from collections .abc import Iterator
22from dataclasses import dataclass
3+ from typing import get_type_hints
34
4- from .attributes import Attribute
5+ from .attributes import Attribute , AttrR , AttrW , AttrRW
56from .controller import BaseController , Controller
67from .cs_methods import Command , Put , Scan
78from .wrappers import WrappedMethod
@@ -41,7 +42,6 @@ def _get_single_mapping(controller: BaseController) -> SingleMapping:
4142 scan_methods : dict [str , Scan ] = {}
4243 put_methods : dict [str , Put ] = {}
4344 command_methods : dict [str , Command ] = {}
44- attributes : dict [str , Attribute ] = {}
4545 for attr_name in dir (controller ):
4646 attr = getattr (controller , attr_name )
4747 match attr :
@@ -51,8 +51,33 @@ def _get_single_mapping(controller: BaseController) -> SingleMapping:
5151 scan_methods [attr_name ] = scan_method
5252 case WrappedMethod (fastcs_method = Command (enabled = True ) as command_method ):
5353 command_methods [attr_name ] = command_method
54- case Attribute (enabled = True ):
55- attributes [attr_name ] = attr
54+
55+ attributes : dict [str , Attribute ] = {}
56+ for name in list (get_type_hints (type (controller ))) + dir (type (controller )):
57+ if (
58+ isinstance (
59+ (attr := getattr (controller , name , None )), AttrRW | AttrR | AttrW
60+ )
61+ and attr .enabled
62+ ):
63+ attributes [name ] = attr
64+
65+ object_defined_attributes = {
66+ name : attr for name , attr in controller .get_attributes ().items () if attr .enabled
67+ }
68+
69+ if conflicting_keys := {
70+ key
71+ for key in object_defined_attributes .keys () & attributes .keys ()
72+ if object_defined_attributes [key ] is not attributes [key ]
73+ }:
74+ raise TypeError (
75+ f"{ controller } has conflicting attributes between those passed in"
76+ "`get_attributes` and those obtained from the class definition: "
77+ f"{ conflicting_keys } "
78+ )
79+
80+ attributes .update (object_defined_attributes )
5681
5782 return SingleMapping (
5883 controller , scan_methods , put_methods , command_methods , attributes
0 commit comments