Issue with reserved keyword Expression members in python client 0.4.4
hunnybear opened this issue ยท 2 comments
while probably not actually related causally, this is definitely in the same code as issue #440
Client and server version 0.4.4, running Python client on python 3.5.2 on windows
When I attempt to create an 'and' expression with code like below:
alt_expr = conn.krpc.Expression.and_(
alt_gen(
conn.krpc.Expression.call(alt_callable),
conn.krpc.Expression.constant_double(altitude)
),
v_speed_gen(
conn.krpc.Expression.call(v_speed_callable),
conn.krpc.Expression.constant_double(0)
)
)
event = conn.krpc.add_event(alt_expr)
I get an error that Expression has no attribute 'and_'.
Traceback (most recent call last):
File "tutorials/sub_orbital.py", line 42, in <module>
run()
File "tutorials/sub_orbital.py", line 37, in run
hb_ksp.vessel.wait_for_surface_altitude_event(conn, vessel, 4000, direction=const.DESCENDING)
File "c:\users\tyler jachetta\projects\ksp_scripts\src\hb_ksp\hb_ksp\vessel.py", line 69, in wait_for_surface_altitude_event
event = get_surface_altitude_event(conn, vessel, altitude)
File "c:\users\tyler jachetta\projects\ksp_scripts\src\hb_ksp\hb_ksp\vessel.py", line 54, in get_surface_altitude_event
alt_expr = conn.krpc.Expression.and_(
AttributeError: type object 'Expression' has no attribute 'and_'
This is further confirmed when I attempt to look at the Expression object in the REPL:
>>> krpc.__version__
'0.4.4'
>>> conn = util.get_conn('test')
>>> conn
<krpc.client.Client object at 0x0000023408A1C2E8>
>>> conn.krpc.Expression.and_
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: type object 'Expression' has no attribute 'and_'
>>> dir(conn.krpc.Expression)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_add_method', '_add_property', '_add_static_method', '_class_name', '_client', '_service_name', 'add', 'aggregate', 'aggregate_with_seed', 'all', 'and', 'any', 'average', 'call', 'cast', 'concat', 'constant_bool', 'constant_double', 'constant_float', 'constant_int', 'constant_string', 'contains', 'count', 'create_dictionary', 'create_list', 'create_set', 'create_tuple', 'divide', 'equal', 'exclusive_or', 'function', 'get', 'greater_than', 'greater_than_or_equal', 'invoke', 'left_shift', 'less_than', 'less_than_or_equal', 'max', 'min', 'modulo', 'multiply', 'not', 'not_equal', 'or', 'order_by', 'parameter', 'power', 'right_shift', 'select', 'subtract', 'sum', 'to_list', 'to_set', 'where']
>>>
Am I doing something wrong here? I haven't delved too deep into krpc yet, but this is really confusing me right now.
Just adding a bit of extra information as I dig in:
it looks like _update_param_names works fine, but it's not being called for conn.krpc.Expression. I added some print debugging to _update_param_names to print things out whenever keywords were found, and during my full script ( @djungelorm I've got a few files that are in play here, do you want me to craft up a single simple script that reproduces this, too? I can, but if you don't need it I won't bother) this was my console output:
found keyword from
finished _update_param_names, names: ['position', 'from', 'to']
finished _update_param_names, newnames: ['position', 'from_', 'to']
found keyword from
finished _update_param_names, names: ['position', 'from', 'to']
finished _update_param_names, newnames: ['position', 'from_', 'to']
found keyword from
finished _update_param_names, names: ['direction', 'from', 'to']
finished _update_param_names, newnames: ['direction', 'from_', 'to']
found keyword from
finished _update_param_names, names: ['direction', 'from', 'to']
finished _update_param_names, newnames: ['direction', 'from_', 'to']
found keyword from
finished _update_param_names, names: ['rotation', 'from', 'to']
finished _update_param_names, newnames: ['rotation', 'from_', 'to']
found keyword from
finished _update_param_names, names: ['rotation', 'from', 'to']
finished _update_param_names, newnames: ['rotation', 'from_', 'to']
found keyword from
finished _update_param_names, names: ['position', 'velocity', 'from', 'to']
finished _update_param_names, newnames: ['position', 'velocity', 'from_', 'to']
found keyword from
finished _update_param_names, names: ['position', 'velocity', 'from', 'to']
finished _update_param_names, newnames: ['position', 'velocity', 'from_', 'to']
Launch!
low solid fuel.
Traceback (most recent call last):
File "C:\Users\Tyler Jachetta\projects\ksp_scripts\src\tutorials\sub_orbital.py", line 45, in <module>
run()
File "C:\Users\Tyler Jachetta\projects\ksp_scripts\src\tutorials\sub_orbital.py", line 40, in run
hb_ksp.vessel.wait_for_surface_altitude_event(conn, vessel, 4000, direction=const.DESCENDING)
File "c:\users\tyler jachetta\projects\ksp_scripts\src\hb_ksp\hb_ksp\vessel.py", line 69, in wait_for_surface_altitude_event
event = get_surface_altitude_event(conn, vessel, altitude)
File "c:\users\tyler jachetta\projects\ksp_scripts\src\hb_ksp\hb_ksp\vessel.py", line 54, in get_surface_altitude_event
alt_expr = conn.krpc.Expression.and_(
AttributeError: type object 'Expression' has no attribute 'and_'
```[](url)
I was mistaken in #440... Only method parameters were being renamed to avoid clashing with keywords, not the name of the method itself. I've fixed this in v0.4.4.post1 (released on pypi) so that code should now work.