Ticket #236 (closed enhancement: fixed)

Opened 18 months ago

Last modified 9 months ago

Python methods on corresponding C types (float/int)

Reported by: scoder Owned by: scoder
Priority: minor Milestone: 0.12.1
Component: Pure Python Mode Keywords:
Cc:

Description

It would be nice if Cython could emulate the instance methods of Python types on the corresponding C types (such as int or float). That way, you could say

    cdef float f = 0.5
    print f.is_integer()

This would not necessarily be efficiently implemented as plain C code (especially when there is no trivial implementation or corresponding C-API call). It's only meant to make C types a bit simpler to use from a Python POV.

Change History

Changed 9 months ago by dagss

  • milestone changed from wishlist to 0.13

Changed 9 months ago by dagss

#460 makes this even ticket more attractive than it seems initially.

Changed 9 months ago by scoder

  • owner changed from somebody to scoder
  • status changed from new to assigned

This is rather easy to achieve by simply coercing the value to a Python object and calling the method on that. The rest would be optimisations for cases where it matters (see OptimizeBuiltinCalls in Optimize.py for a long list of similar cases).

Implemented in

 http://hg.cython.org/cython-devel/rev/56bc793d18e0

Changed 9 months ago by scoder

  • status changed from assigned to closed
  • resolution set to fixed

Changed 9 months ago by scoder

  • milestone changed from 0.13 to 0.12.1

Changed 9 months ago by scoder

Note: See TracTickets for help on using tickets.