mirror of
				https://github.com/KevinMidboe/python-gpiozero.git
				synced 2025-10-29 17:50:37 +00:00 
			
		
		
		
	Fix #28
Re-order the test bindings to prefer using no parameters if possible
This commit is contained in:
		| @@ -75,18 +75,20 @@ class WaitableInputDevice(InputDevice): | |||||||
|             raise InputDeviceError('value must be None or a callable') |             raise InputDeviceError('value must be None or a callable') | ||||||
|         else: |         else: | ||||||
|             # Try binding ourselves to the argspec of the provided callable. |             # Try binding ourselves to the argspec of the provided callable. | ||||||
|             # If this works, assume the function is capable of accepting us |             # If this works, assume the function is capable of accepting no | ||||||
|             # as the only (mandatory) parameter. |             # parameters | ||||||
|             try: |             try: | ||||||
|                 inspect.getcallargs(fn, self) |                 inspect.getcallargs(fn) | ||||||
|                 @wraps(fn) |                 return fn | ||||||
|                 def wrapper(): |  | ||||||
|                     return fn(self) |  | ||||||
|                 return wrapper |  | ||||||
|             except TypeError: |             except TypeError: | ||||||
|                 try: |                 try: | ||||||
|                     inspect.getcallargs(fn) |                     # If the above fails, try binding with a single parameter | ||||||
|                     return fn |                     # (ourselves). If this works, wrap the specified callback | ||||||
|  |                     inspect.getcallargs(fn, self) | ||||||
|  |                     @wraps(fn) | ||||||
|  |                     def wrapper(): | ||||||
|  |                         return fn(self) | ||||||
|  |                     return wrapper | ||||||
|                 except TypeError: |                 except TypeError: | ||||||
|                     raise InputDeviceError( |                     raise InputDeviceError( | ||||||
|                         'value must be a callable which accepts up to one ' |                         'value must be a callable which accepts up to one ' | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user