From: William S F. <ws...@fu...> - 2008-09-29 20:47:41
|
Haoyu Bai wrote: > On Sun, Sep 14, 2008 at 2:09 AM, Richard Boulton > <ri...@le...> wrote: >> Haoyu Bai wrote: >>>> Please add to the documentation any limitations, eg overloaded methods >>>> don't >>>> get annotated. This particular limitation is quite a biggy. Any plans to >>>> fix? >>>> >>> Okey, I documented this limitation yet. For fixing this, I can't >>> figure out how right now. All functions overloaded the same name will >>> share the same proxy function, so there's no way to distinguish them. >>> Also, there's no built-in support of overloading in Python. >> Perhaps we could supply partial annotations in such cases. It's quite often >> for the type of some parameters to be common between the different >> overloaded forms. So, for example, if we had the four functions: >> >> void foo(); >> void foo(const char * name); >> void foo(const char * name, int number); >> void foo(const char * name, float number); >> >> A reasonable annotated wrapper might be: >> >> def foo(name : "const char *", number): >> >> >> Here, the first parameter is always of type "const char *" (or absent), so >> we can unambiguously annotate it. The second parameter, when present, has >> two different types, so we can't annotate it. >> >> I'm not sure if such annotations will actually be particularly useful >> (though it would allow an editor which understood the annotations to do some >> useful hinting, I suppose), but this seems like the most plausible and >> consistent behaviour. >> >> -- >> Richard >> > > That's a better solution, I will have a try. > Would it make sense to annotate with all the available options using some sort of separation character like '|' ? Then you would have: def foo(name : "| const char *", number : "| int | float"): noting that if there is nothing before the first '|' the parameter is then optional. William |