lcm-proj / lcm

Lightweight Communications and Marshalling
GNU Lesser General Public License v2.1
944 stars 385 forks source link

lcm-gen python: pyright hates import syntax used #470

Closed judfs closed 4 months ago

judfs commented 9 months ago

Consider the following:

Add node_pair_t.lcm to the example package:

package exlcm;

struct node_pair_t
{
    exlcm.node_t   head;
    exlcm.node_t   tail;
}

node_pair_t.py looks like

...
import exlcm.node_t

class node_pair_t(object):
...
    def __init__(self):
        self.head = exlcm.node_t()
        self.tail = exlcm.node_t()
...

This causes Module is not callable Pylance [reportGeneralTypeIssues] and (variable) head: Unknown to be reported. Therefore if I type import exlcm; foo = exlcm.node_pair_t(); foo.head.num_children, my editor does not know what head is and therefore does not know what num_children is.

Things work at all because __init__.py has the line from .node_t import node_t. And that is even how I create foo above.

Things seem to be happy if self.head = exlcm.node_t.node_t() were to be emitted instead. (Does not run, pyright is bugged in accepting this)

Looking at emit_member_initializer in lcmgen/emit_python.c.


Why is it done the way it is?

Can/Should the fprintf(f, "%s()", tn); line be changed?

judfs commented 9 months ago

fprintf(f, "%s.%s()", tn, lm->type->shortname); would fix emit_member_initializer / emit_python_init.

Having trouble finding where the lcm_member_t values are created if changing the lctypename value would be preferred.

judfs commented 7 months ago

After looking through emit c, I suppose names are generated and then individual emitters are expected to modify them as needed? Looks like the above change should be the say to go.

judfs commented 6 months ago

Hitting a bug in pyright they won't fix: https://github.com/microsoft/pyright/issues/6674. My previous proposed solution was also wrong because of this bug.

nosracd commented 4 months ago

Resolved by #491