On 10/31/2010 07:09 AM, Stefan Behnel wrote:
> Robert Bradshaw, 31.10.2010 04:34:
>    
>> On Sat, Oct 30, 2010 at 2:12 PM, Lisandro Dalcin wrote:
>>      
>>> On 30 October 2010 22:16, Stefan Behnel wrote:
>>>        
>>>> a while ago, we had agreed that a "final" directive would be nice to have
>>>> for cdef classes. I implemented the basics for that (i.e. "final" types are
>>>> no longer subclassable from Python), and I also added an "internal"
>>>> directive that prevents a type from appearing in the module dict. So you
>>>> can now write something like this for a type that you only use internally
>>>> in your module:
>>>>
>>>>      @cython.final
>>>>      @cython.internal
>>>>      cdef class _MyInternalType:
>>>>         ...
>>>>
>>>> http://trac.cython.org/cython_trac/ticket/263
>>>> http://trac.cython.org/cython_trac/ticket/585
>>>>
>>>>          
>>> Many thanks for this, Stefan!
>>>        
> I'm as happy as you are.
>
>
>    
>>>> I think the "final" directive name was pretty much agreed on, but what
>>>> about the "internal" directive? Any objections to that?
>>>>          
>>> Perhaps "private" ? I still prefer "internal".
>>>        
>> I'd lean towards "private" but that's not a strong preference.
>>      
> I may be mistaken, but it looks like we don't actually use "private"
> anywhere in the language so far. I thought we did, but it currently seems
> to be a purely internal visibility marker. So to me, "internal" makes as
> much sense as "private".
>
> Robert, if you want me to change it, just say so clearly. ;)
>
>
>   >  I also
>   >  don't think such a feature is strictly necessary and complicates the
>   >  language, but wouldn't stand in its way if I'm the only one.
>
> I just wrote a patch for lxml.etree that adds one or both of the decorators
> where they make sense. (I won't apply it right away as the next release is
> hopefully closer than the next release of Cython, but I'll keep it around
> for one of the next releases after Cython 0.13.1.)
>
> It turns out that out of the 117 extension types in lxml.etree, 39 would be
> happy about at least one of the decorators: 30x final and 36x internal. So
> almost every third class is an internal one. Most of them are context
> classes that are passed through C in one way or another and that are used
> by internal callback code. Pure implementation details that no user should
> ever mess around with or even care about.
>    

Well, a lot of pure Python libraries have "pure implementation details 
that no user should ever mess around with or care about". The Python way 
is by convention (like a leading underscore telling people to just stay 
away), not by enforcement.

Is the rationale that it is more important to protect possibly 
non-segfaulting Cython code than always-safe Python code?

I guess I just don't see the usecase...prepend an underscore to 
module-internal class names, and that's it?

Regarding final, I see more of a usecase for individual methods than 
classes. I'm +0 for final on classes (Python doesn't have such a 
feature, why should we?), it is locking down individual methods (for 
possible speedups) that is important to me (in this case we can argue 
why Cython should have something Python does not).

Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to