2424
2525from robot .api .deco import keyword # noqa F401
2626
27- __version__ = ' 3.0.1.dev1'
27+ __version__ = " 3.0.1.dev1"
2828
2929
3030class HybridCore :
31-
3231 def __init__ (self , library_components ):
3332 self .keywords = {}
3433 self .keywords_spec = {}
@@ -37,10 +36,10 @@ def __init__(self, library_components):
3736 self .add_library_components ([self ])
3837
3938 def add_library_components (self , library_components ):
40- self .keywords_spec [' __init__' ] = KeywordBuilder .build (self .__init__ )
39+ self .keywords_spec [" __init__" ] = KeywordBuilder .build (self .__init__ )
4140 for component in library_components :
4241 for name , func in self .__get_members (component ):
43- if callable (func ) and hasattr (func , ' robot_name' ):
42+ if callable (func ) and hasattr (func , " robot_name" ):
4443 kw = getattr (component , name )
4544 kw_name = func .robot_name or name
4645 self .keywords [kw_name ] = kw
@@ -53,12 +52,14 @@ def __get_members(self, component):
5352 if inspect .ismodule (component ):
5453 return inspect .getmembers (component )
5554 if inspect .isclass (component ):
56- raise TypeError ('Libraries must be modules or instances, got '
57- 'class {!r} instead.' .format (component .__name__ ))
55+ raise TypeError (
56+ "Libraries must be modules or instances, got " "class {!r} instead." .format (component .__name__ )
57+ )
5858 if type (component ) != component .__class__ :
59- raise TypeError ('Libraries must be modules or new-style class '
60- 'instances, got old-style class {!r} instead.'
61- .format (component .__class__ .__name__ ))
59+ raise TypeError (
60+ "Libraries must be modules or new-style class "
61+ "instances, got old-style class {!r} instead." .format (component .__class__ .__name__ )
62+ )
6263 return self .__get_members_from_instance (component )
6364
6465 def __get_members_from_instance (self , instance ):
@@ -71,8 +72,7 @@ def __get_members_from_instance(self, instance):
7172 def __getattr__ (self , name ):
7273 if name in self .attributes :
7374 return self .attributes [name ]
74- raise AttributeError ('{!r} object has no attribute {!r}'
75- .format (type (self ).__name__ , name ))
75+ raise AttributeError ("{!r} object has no attribute {!r}" .format (type (self ).__name__ , name ))
7676
7777 def __dir__ (self ):
7878 my_attrs = super ().__dir__ ()
@@ -83,7 +83,6 @@ def get_keyword_names(self):
8383
8484
8585class DynamicCore (HybridCore ):
86-
8786 def run_keyword (self , name , args , kwargs = None ):
8887 return self .keywords [name ](* args , ** (kwargs or {}))
8988
@@ -95,8 +94,8 @@ def get_keyword_tags(self, name):
9594 return self .keywords [name ].robot_tags
9695
9796 def get_keyword_documentation (self , name ):
98- if name == ' __intro__' :
99- return inspect .getdoc (self ) or ''
97+ if name == " __intro__" :
98+ return inspect .getdoc (self ) or ""
10099 spec = self .keywords_spec .get (name )
101100 return spec .documentation
102101
@@ -107,9 +106,9 @@ def get_keyword_types(self, name):
107106 return spec .argument_types
108107
109108 def __get_keyword (self , keyword_name ):
110- if keyword_name == ' __init__' :
109+ if keyword_name == " __init__" :
111110 return self .__init__
112- if keyword_name .startswith ('__' ) and keyword_name .endswith ('__' ):
111+ if keyword_name .startswith ("__" ) and keyword_name .endswith ("__" ):
113112 return None
114113 method = self .keywords .get (keyword_name )
115114 if not method :
@@ -121,11 +120,11 @@ def get_keyword_source(self, keyword_name):
121120 path = self .__get_keyword_path (method )
122121 line_number = self .__get_keyword_line (method )
123122 if path and line_number :
124- return ' {}:{}' .format (path , line_number )
123+ return " {}:{}" .format (path , line_number )
125124 if path :
126125 return path
127126 if line_number :
128- return ' :%s' % line_number
127+ return " :%s" % line_number
129128 return None
130129
131130 def __get_keyword_line (self , method ):
@@ -134,7 +133,7 @@ def __get_keyword_line(self, method):
134133 except (OSError , TypeError ):
135134 return None
136135 for increment , line in enumerate (lines ):
137- if line .strip ().startswith (' def ' ):
136+ if line .strip ().startswith (" def " ):
138137 return line_number + increment
139138 return line_number
140139
@@ -146,13 +145,12 @@ def __get_keyword_path(self, method):
146145
147146
148147class KeywordBuilder :
149-
150148 @classmethod
151149 def build (cls , function ):
152150 return KeywordSpecification (
153151 argument_specification = cls ._get_arguments (function ),
154- documentation = inspect .getdoc (function ) or '' ,
155- argument_types = cls ._get_types (function )
152+ documentation = inspect .getdoc (function ) or "" ,
153+ argument_types = cls ._get_types (function ),
156154 )
157155
158156 @classmethod
@@ -163,9 +161,7 @@ def unwrap(cls, function):
163161 def _get_arguments (cls , function ):
164162 unwrap_function = cls .unwrap (function )
165163 arg_spec = cls ._get_arg_spec (unwrap_function )
166- argument_specification = cls ._get_default_and_named_args (
167- arg_spec , function
168- )
164+ argument_specification = cls ._get_default_and_named_args (arg_spec , function )
169165 argument_specification .extend (cls ._get_var_args (arg_spec ))
170166 kw_only_args = cls ._get_kw_only (arg_spec )
171167 if kw_only_args :
@@ -198,12 +194,12 @@ def _drop_self_from_args(cls, function, arg_spec):
198194 @classmethod
199195 def _get_var_args (cls , arg_spec ):
200196 if arg_spec .varargs :
201- return [' *%s' % arg_spec .varargs ]
197+ return [" *%s" % arg_spec .varargs ]
202198 return []
203199
204200 @classmethod
205201 def _get_kwargs (cls , arg_spec ):
206- return [' **%s' % arg_spec .varkw ] if arg_spec .varkw else []
202+ return [" **%s" % arg_spec .varkw ] if arg_spec .varkw else []
207203
208204 @classmethod
209205 def _get_kw_only (cls , arg_spec ):
@@ -212,15 +208,15 @@ def _get_kw_only(cls, arg_spec):
212208 if not arg_spec .kwonlydefaults or arg not in arg_spec .kwonlydefaults :
213209 kw_only_args .append (arg )
214210 else :
215- value = arg_spec .kwonlydefaults .get (arg , '' )
211+ value = arg_spec .kwonlydefaults .get (arg , "" )
216212 kw_only_args .append ((arg , value ))
217213 return kw_only_args
218214
219215 @classmethod
220216 def _get_types (cls , function ):
221217 if function is None :
222218 return function
223- types = getattr (function , ' robot_types' , ())
219+ types = getattr (function , " robot_types" , ())
224220 if types is None or types :
225221 return types
226222 return cls ._get_typing_hints (function )
@@ -255,12 +251,11 @@ def _args_as_list(cls, function, arg_spec):
255251 def _get_defaults (cls , arg_spec ):
256252 if not arg_spec .defaults :
257253 return {}
258- names = arg_spec .args [- len (arg_spec .defaults ):]
254+ names = arg_spec .args [- len (arg_spec .defaults ) :]
259255 return zip (names , arg_spec .defaults )
260256
261257
262258class KeywordSpecification :
263-
264259 def __init__ (self , argument_specification = None , documentation = None , argument_types = None ):
265260 self .argument_specification = argument_specification
266261 self .documentation = documentation
0 commit comments