Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

super() within generation function not properly parsed #3246

Closed
vancouvermichael opened this issue Nov 21, 2019 · 1 comment
Closed

super() within generation function not properly parsed #3246

vancouvermichael opened this issue Nov 21, 2019 · 1 comment

Comments

@vancouvermichael
Copy link

vancouvermichael commented Nov 21, 2019

I can import teapot in the interactive python:

#teapot.py
class _A():
    def __init__(self):
        self.a = 1
def _gen(c,AB):
    class ABC(AB):
        def __init__(self):
            super().__init__()
            self.c = c
    return ABC
_AC = _gen(3,_A)
print(_AC)
print(_AC())

But after I cythonize -X language_level=3 -i teapot.py, and start a python interactive session, and import teapot, the interactive session quits directly. After I changed from super() to super(ABC, self), it works.

 Name                    Version                   Build  Channel
cython                    0.29.10          py37h6538335_0    conda-forge
python                    3.7.4                h5263a28_0
@da-woods
Copy link
Contributor

da-woods commented Nov 23, 2019

Code reproduced with correct formatting and simplified slightly:

#teapot.py
class _A():
    def __init__(self):
        self.a = 1
def gen():
    class ABC(_A):
        def __init__(self):
            super().__init__()
    return ABC

ABC = gen()
print(ABC, ABC())

This generates a segmentation fault. The issue seems to be in the C function __pyx_pf_6teapot_gen. Just reproducing a chunk near the end:

  if (__Pyx_CyFunction_InitClassCell(__pyx_t_4, __pyx_t_5) < 0) __PYX_ERR(0, 7, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_ABC = __pyx_t_5;
  __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "teapot.py":10
 *         def __init__(self):
 *             super().__init__()
 *     return ABC             # <<<<<<<<<<<<<<
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_ABC);
  __pyx_r = __pyx_v_ABC;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  goto __pyx_L0;

Note that __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; is included twice and the second one is where it goes wrong. With super(ABC, self) this doesn't happen - however the function is quite different and a scope is generated, so I don't know if comparisons are useful.

I'm not sure I can make any more progress, but this is the start of the diagnosis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants