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

C compilation fails if '__init__' has no return type #792

Closed
JukkaL opened this issue Dec 29, 2020 · 1 comment · Fixed by python/mypy#9866
Closed

C compilation fails if '__init__' has no return type #792

JukkaL opened this issue Dec 29, 2020 · 1 comment · Fixed by python/mypy#9866

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Dec 29, 2020

This program doesn't compile:

class C:
    def __init__(self):
        pass

Here's the output:

...
x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/jukka/src/mypy/mypyc/lib-rt -I/home/jukka/venv/mypy/include -I/usr/include/python3.8 -c build/__native.c -o build/temp.linux-x86_64-3.8/build/__native.o -O3 -Werror -Wno-unused-function -Wno-unused-label -Wno-unreachable-code -Wno-unused-variable -Wno-unused-command-line-argument -Wno-unknown-warning-option -Wno-unused-but-set-variable
build/__native.c: In function ‘CPyDef_C’:
build/__native.c:111:16: error: initialization of ‘char’ from ‘PyObject *’ {aka ‘struct _object *’} makes integer from pointer without a cast [-Werror=int-conversion]
  111 |     char res = CPyDef_C_____init__(self);
      |                ^~~~~~~~~~~~~~~~~~~
...

Maybe we should always give __init__ an implicit None return type.

@thomasjohns
Copy link

I'd like to give this one a try. I think a special case for __init__ in mypyc.irbuild.mapper.py could be a way to solve this.

JukkaL pushed a commit to python/mypy that referenced this issue Jan 8, 2021
Fixes mypyc/mypyc#792.

Always give __init__ an implicit None return type so that programs like

```
class C:
    def __init__(self):  # missing `-> None` annotation
        pass
```

compile.
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.

2 participants