Skip to content

Generated methods like __init__ lack the __module__ attribute #309

@Stewori

Description

@Stewori

This issue was initially reported in Stewori/pytypes#18.
Applying __module__ on e.g. the __init__ function generated by attrs raises a KeyError. For more information please refer to the link above.

Being able to retrieve the module for a given function/method is relevant to locate the function or method in the class hierarchy from perspective of a decorator or profiler. Searching a module top-down for a function/method is often the only way to access its enclosing class, including nesting structure of classes.

A workaround that sometimes worked but not in this case is to get the module via __code__.co_filename. However, any valid approach for identifying the corresponding module and/or location in class hierarchy for a generated function would be fine.

Please apologize if I should overlook some approach that is already viable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions