[Cython] 'local variable referenced before assignment' warnings

Vitja Makarov vitja.makarov at gmail.com
Sat Sep 24 10:08:34 CEST 2011

2011/9/23 mark florisson <markflorisson88 at gmail.com>:
> On 23 September 2011 06:02, Robert Bradshaw
> <robertwb at math.washington.edu> wrote:
>> On Thu, Sep 22, 2011 at 9:36 PM, Vitja Makarov <vitja.makarov at gmail.com> wrote:
>>> 2011/9/23 Robert Bradshaw <robertwb at math.washington.edu>:
>>>> On Thu, Sep 22, 2011 at 5:08 AM, Vitja Makarov <vitja.makarov at gmail.com> wrote:
>>>>> 2011/9/22 Robert Bradshaw <robertwb at math.washington.edu>:
>>>>>> On Wed, Sep 21, 2011 at 1:20 AM,  <robert.rex at exasol.com> wrote:
>>>>>>> Hi Robert,
>>>>>>> Robert Bradshaw wrote:
>>>>>>>> The warning seem correct to me, or is foo actually modifying the
>>>>>>>> values of cya and cyb? (I suppose this could be possible by taking the
>>>>>>>> address of the "passed by reference" arguments, but would seem like a
>>>>>>>> *very* poor API design.)
>>>>>>> thanks for your fast answer! What made me came up with this issue is
>>>>>>> that GCC/C++ will not complain in similar situations in C++ code (and
>>>>>>> assumes foo() to initialize/change the value of cya/cyb). Thus, there
>>>>>>> is an (arguable) difference in C++ compiler/Cython warnings.
>>>>>> Yes, in C++ the called function can modify values passed by reference,
>>>>>> so we need to add this exception to Cython.
>>>>> That could be hard because we can not always resolve function to check
>>>>> its args at create-control-flow stage.
>>>> Doesn't this always happen after declaration analysis?
>>> Sure. But before analyse expressions, so you have to manually lookup
>>> entries for names and attributes.
>> Ah, yes.
>>> I see two cases here: global function call and method call. Both are
>>> SimpleCallNodes.
>> Yep, and the function could be an arbitrary expression... Ugly.
> As a simple hack, couldn't you in case of a SimpleCallNode where the
> function is a NameNode check if the arguments are passed by reference,
> and if so not issue the warning. If the callnode.function is an
> arbitrary expression (like casting a pointer to such a function), then
> you just issue the warning. Then you will cover probably at least 95%
> of the cases.

Yeah, most popular cases would be function call and method call. We
can handle both of them but I'm still not sure that this is a good
Maybe it's better to disable this warning by default.


More information about the cython-devel mailing list