Robert Bradshaw wrote:
> On Sep 16, 2009, at 7:45 AM, Lisandro Dalcin wrote:
>
>> On Wed, Sep 16, 2009 at 5:49 AM, Dag Sverre Seljebotn
>> <[email protected]> wrote:
>>> Stefan Behnel wrote:
>>>> Dag Sverre Seljebotn wrote:
>>>>
>>>>> A directive to warn/give error on any undeclared variables? I.e.:
>>>>>
>>>>> @cython.warning_undeclared(True)
>>>>> def foo():
>>>>> cdef object a
>>>>> cdef int b
>>>>> a = b = c = 3 # warns that "c" is not declared and auto-
>>>>> typed to object
>>>>>
>> Dag, take for granted that anything that Cython adds in this
>> direction, I'm going to use once it is ready... and likely these
>> directives will be globally enabled by default.
>>
>> However, there is something that makes me uncomfortable about this...
>> This is not quite similar to other compiler directives... I mean, it
>> has no effect in Cython semantics or generated C code. Just a coment,
>> not a big deal...
>>
>> In the same spirit, Cython could have a "directive" to emit warnings
>> when a bare "object" is implicitly cast to a builtin/cdef type.
>>
>> Final note: we could potentially have many warning-related directives,
>> right? Having a lot will not harm, right? Then perhaps we should have
>> a dict-like "warning" directive, and you use like this:
>>
>> @cython.warning(undeclared=True,untyped=True,cast_implicit=True)
>> cdef void foo(a): # "a" is untyped
>> cdef list b
>> cdef object c
>> b = a # implicit downcast object -> list
>> c = b
>> d = c # 'd' undeclared
>
> +1 I like this warning decorator. Perhaps we could also take a -Wxxx
> flags like gcc. I'd rather it not be on by default however.
OK. I'd rather prefer this to be treated as "warning_undeclared" and so
on internally though. Yet another layer of manually handled dictionary
stack is a bit too much for me personally :-)
And also I suppose @cython.error should be provided as well just for
fun. So that makes it (internally) something like:
if is_undeclared and env.directives["errlevel_undeclared"]:
Errors.report(MY_MSG, env.directives["errlevel_undeclared"])
errlevel would be None, Errors.ERROR or Errors.WARNING. Sounds ok?
(This partially overlaps with the existing warning level system for
"seriousness" of warnings, which I think can just be ripped out in
favour of this eventually.)
--
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev