Opened 7 years ago

Closed 3 years ago

Last modified 3 years ago

#5 closed defect (fixed)

no mangling of double underscore names in class

Reported by: robertwb Owned by: scoder
Priority: major Milestone: 0.16
Component: Python Semantics Keywords:
Cc:

Description (last modified by scoder)

When defining a class attribute that starts with double underscores, CPython mangles the name from __bla to _classname_bla, but Cython produced classes don't.

Minimal example:

test.pyx and good.py are the same, like so:
class Test(object):
    __bla = 1

alon@alfajor:~/src/bugs/cython/doubleunderscore$ python
Python 2.5.2 (r252:60911, Feb 26 2008, 15:04:22)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import test
>>> test.Test
<class 'test.Test'>
>>> test.Test.__bla
1
>>>
alon@alfajor:~/src/bugs/cython/doubleunderscore$
alon@alfajor:~/src/bugs/cython/doubleunderscore$ ls
build setup.py test.c test.pyx test.so
alon@alfajor:~/src/bugs/cython/doubleunderscore$ cp test.pyx good.py
alon@alfajor:~/src/bugs/cython/doubleunderscore$ python
Python 2.5.2 (r252:60911, Feb 26 2008, 15:04:22)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import good
>>> good.Test
<class 'good.Test'>
>>> good.Test.__bla
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'Test' has no attribute '__bla'
>>> good.Test._Test__bla
1
>>>

Change History (10)

comment:1 Changed 7 years ago by robertwb

  • Owner changed from robertwb to somebody

comment:2 Changed 6 years ago by robertwb

  • Priority changed from major to minor

comment:3 Changed 6 years ago by robertwb

  • Milestone set to wishlist

comment:4 Changed 6 years ago by Stefan Behnel

  • Component changed from Build System to Code Generation

I added a test case for this as tests/unimplemented/methodmangling.pyx

comment:5 Changed 6 years ago by scoder

  • Description modified (diff)
  • Milestone changed from wishlist to 1.0

comment:6 Changed 6 years ago by scoder

  • Description modified (diff)

comment:7 Changed 4 years ago by scoder

  • Component changed from Code Generation to Python Semantics

comment:8 Changed 3 years ago by scoder

  • Owner changed from somebody to scoder
  • Status changed from new to assigned

comment:9 Changed 3 years ago by scoder

  • Milestone changed from 1.0 to 0.15.1
  • Priority changed from minor to major
  • Resolution set to fixed
  • Status changed from assigned to closed

comment:10 Changed 3 years ago by scoder

  • Milestone changed from 0.15.1 to 0.16
Note: See TracTickets for help on using tickets.