Optimise maybeWarnDeprecated

Bug #597594 reported by Christian Zagrodnick
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Zope 2
Fix Released
Low
Christian Zagrodnick

Bug Description

OFS.subscriber.maybeWarnDeprecated checks if a deprecation warning should be sent.

There are two ways for classes to avoid the warning: ZCML and the __five_method__ attribute on the method.

maybeWarnDeprecated first checks the ZCML registered classes by iterating over a list:

    for cls in deprecatedManageAddDeleteClasses:
        if isinstance(ob, cls):
            # Already deprecated through zcml
            return

and then checking for __five_method__:

    if getattr(getattr(ob, method_name), '__five_method__', False):
        # Method knows it's deprecated
        return

IMHO those two checks should be reversed: first check for the attribute, then for the ZCML registered: checking for the attribute is *much* faster and is hit by common cases where a class is just subclassing an OFS.ObjectManager.ObjectManager.

(I noticed that during test setup where various DirectoryViews are created; the run time drops from 180s to 2s)

Anyone seconding that?

Revision history for this message
Hanno Schlichting (hannosch) wrote :

Sounds good to me. Maybe adding a first path for checking direct types without subtypes could help as well, something like:

ob_type = type(ob)
if ob_type in deprecatedManageAddDeleteClasses:
    return

for cls in deprecatedManageAddDeleteClasses:
    if issubclass(ob_type, cls):
        return

Revision history for this message
Christian Zagrodnick (zagy) wrote :

Sounds good. I'll do that :)

Changed in zope2:
assignee: nobody → Christian Zagrodnick (zagy)
status: New → Confirmed
Changed in zope2:
status: Confirmed → In Progress
Revision history for this message
Christian Zagrodnick (zagy) wrote :

2.12 r113793

Revision history for this message
Christian Zagrodnick (zagy) wrote :

trunk r113794

Changed in zope2:
status: In Progress → Fix Committed
Changed in zope2:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.