FastBinaryEncoding icon indicating copy to clipboard operation
FastBinaryEncoding copied to clipboard

Small issue with generated python code

Open paulorsouza opened this issue 5 months ago • 0 comments

Hello @chronoxor , we use fbe in our cpp an c# app, we decided to use in our python app too, but we encountered a small problem. In our schemes we use the same name as the strucs in the fields on other strucst. This works well in c# and cpp, but in python it creates a shadowing problem.

struct InstrumentId {
   Source Source
   Venue Venue
    ...
}
class InstrumentId(object):
    __slots__ = "Source", "SecurityId", "Symbol", 

    def __init__(self, Source=None, SecurityId=0, Symbol=""):
        if Source is None:
            Source = Source()
        self.Source = Source

Source was shadowed here, I temporarily solve it by changing the field name to _Source, but i'd like to know if you can help us with a definitive solution.

Naively I think that adding prefix to all parameters in init will solve the problem, but I'm not sure.

https://github.com/chronoxor/FastBinaryEncoding/blob/master/source/generator_python.cpp#L3256

Thanks in advance for your attention

paulorsouza avatar Jan 29 '24 18:01 paulorsouza