@@ -44,15 +44,20 @@ class HybridCore(object):
44
44
45
45
def __init__ (self , library_components ):
46
46
self .keywords = {}
47
+ self .attributes = {}
47
48
self .add_library_components (library_components )
48
49
self .add_library_components ([self ])
49
50
50
51
def add_library_components (self , library_components ):
51
52
for component in library_components :
52
53
for name , func in self ._get_members (component ):
53
54
if callable (func ) and hasattr (func , 'robot_name' ):
55
+ kw = getattr (component , name )
54
56
kw_name = func .robot_name or name
55
- self .keywords [kw_name ] = getattr (component , name )
57
+ self .keywords [kw_name ] = kw
58
+ # Expose keywords as attributes both using original
59
+ # method names as well as possible custom names.
60
+ self .attributes [name ] = self .attributes [kw_name ] = kw
56
61
57
62
def _get_members (self , component ):
58
63
if inspect .ismodule (component ):
@@ -64,18 +69,18 @@ def _get_members(self, component):
64
69
raise TypeError ('Libraries must be modules or new-style class '
65
70
'instances, got old-style class {!r} instead.'
66
71
.format (component .__class__ .__name__ ))
67
- return self ._get_members_from_instannce (component )
72
+ return self ._get_members_from_instance (component )
68
73
69
- def _get_members_from_instannce (self , instance ):
74
+ def _get_members_from_instance (self , instance ):
70
75
# Avoid calling properties by getting members from class, not instance.
71
76
cls = type (instance )
72
77
for name in dir (instance ):
73
78
owner = cls if hasattr (cls , name ) else instance
74
79
yield name , getattr (owner , name )
75
80
76
81
def __getattr__ (self , name ):
77
- if name in self .keywords :
78
- return self .keywords [name ]
82
+ if name in self .attributes :
83
+ return self .attributes [name ]
79
84
raise AttributeError ('{!r} object has no attribute {!r}'
80
85
.format (type (self ).__name__ , name ))
81
86
@@ -84,7 +89,7 @@ def __dir__(self):
84
89
my_attrs = dir (type (self )) + list (self .__dict__ )
85
90
else :
86
91
my_attrs = super ().__dir__ ()
87
- return sorted (set (my_attrs + list (self .keywords ) ))
92
+ return sorted (set (my_attrs ) | set (self .attributes ))
88
93
89
94
def get_keyword_names (self ):
90
95
return sorted (self .keywords )
0 commit comments