Opened 7 years ago

Closed 5 years ago

#422 closed defect (fixed)

bug in setting __module__

Reported by: Fernando Perez Owned by: haoyu
Priority: major Milestone: wishlist
Component: Code Generation Keywords:
Cc: biahaoyu@…


Hi folks,

I'm wondering if this is expected behavior.  Consider some trivial
little class like

class Simpleton:
   def __str__(self):
       return "A simpleton"

   def incr(self,x):
       """Increment x by one.


s = Simpleton()
       return x+1

If I build this thing in cython, the Simpleton.incr.__module__
attribute is set to None, while if I make it a pure python module,
it's correctly set to the module name:

In [18]: p sprimes.primes.Simpleton.incr.__module__

In [19]: p sprimes.pyprimes.Simpleton.incr.__module__

This difference causes the doctest to miss any doctest examples that
might be included in the methods.

Note that for *top-level* functions in the extension module, the
__module__ attribute is correctly set:

In [21]: p sprimes.primes.primes
<built-in function primes>

In [22]: p sprimes.primes.primes.__module__

so the problem appears to be only for classes.

This is running cython 0.9.8.

Thanks for any feedback,


Attachments (1)

fix_T422.patch (5.0 KB) - added by haoyu 6 years ago.
Revised version of the patch which using PyStringConst?

Download all attachments as: .zip

Change History (6)

comment:1 Changed 6 years ago by haoyu

This is due to PyFunction_New creates the PyFunction? with the module set as NULL. We should call PyFunction_NewEx, which accepts a PyObject? as module name.

comment:2 Changed 6 years ago by haoyu

  • Cc biahaoyu@… added

comment:3 Changed 6 years ago by robertwb

It may be worth creating the PyObject?? module name at module load time (do we do that already), and simply re-using that, rather than re-creating it for every function.

Binding functions need to be changed as well.

Changed 6 years ago by haoyu

Revised version of the patch which using PyStringConst?

comment:4 Changed 6 years ago by haoyu

  • Owner changed from somebody to haoyu

comment:5 Changed 5 years ago by haoyu

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.