PyCharm: __init__ Signature is not compatible to __new__

Answered

New version of PyCharm seems to give me this warning on pretty much every class that has parameters to __init__

Is there an issue with this inspection -- the default __new__ has no parameters and does nothing, but that's nothing to generate a warning about, is it?

Or am I missing some new 'best practice' around defining parameters for __init__()  ?

thanks for any help - these stray warnings are very annoying.

16 comments

These spurious warnings disappeared after re-starting PyCharm -- sorry for the false alarm, should have tried that first.

In research this though, I did find a couple of related spurious warnings I can't resolve:

1)  "Signature not compatible to __init__" where  ModelBase class extends (type) and does not define __init__:
Yet this overrides models.base.ModelBase with exactly the same signature:

2) "Class has no __init__ method" - where base class definitely does define __init__

UserAdmin extends django.contrib.auth.admin.UserAdmin, which extends django.contrib.admin.option.ModelAdmin, which defines:

def __init__(self, model, admin_site)

These are not pressing and don't bother me much, but I'm curious if some of PyCharm's warnings truly are spurious, or do these cases really violate some principle?

thanks!

0

Hi Jfall Capilanou! I believe first problem is covered by PY-22936. The second is a tricky one, if I understood you correctly the problem is PyCharm gets confused by the UserAdmin redeclaration in your code. I created a ticket for this problem: PY-24436.

0

Yep -- that's it.  Thanks!!  very helpful :-)

0

This seems to be back in version:

PyCharm 2018.2.4 (Community Edition)
Build #PC-182.4505.26, built on September 19, 2018
JRE: 1.8.0_152-release-1248-b8 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.18.0-2-amd64

The whole file is exactly 3 lines:

class Whatever(object):
     def __init__(self, name):
         self.name = name

0

Hi Mauro,

I do not observe this in 2018.2.4. Could you please try 'File | Invalidate Caches / Restart...`?

0

Hi Sergey,

I tried invalidating caches, but nothing changed.

My machine is an up-to-date Debian "sid" (unstable) installation.

Interpreter (if it matters) is "Python 3.6.1 (/usr/bin/python3.6)"

I am available to do specific tests, if needed, but You will have to tell me what to try.

I also experience the following (possibly unrelated) false positive:

Thanks for the fast answer.

0

Could you please upload a sample project and your settings (https://www.jetbrains.com/help/pycharm/exporting-and-importing-settings.html) to https://uploads.services.jetbrains.com/ zipped and let me know the name of that zip file?

Please try the latest EAP build in the meantime https://www.jetbrains.com/pycharm/nextversion/, does the problem remain?

0

Hi Sergey,

I uploaded the file "anagrafica.zip" which is a snapshot of my real WIP project (thus it has much more than needed).

You can have a look to files "p3.py" and "test.py" (feel free to peruse anything You like, no secrets there ;) )

I will try "nextversion" later to day; I will keep You posted.

Thanks

Mauro

0

Hmm, looks just fine.

Do you have any custom plugins enabled?

Please also upload you logs folder zipped to https://uploads.services.jetbrains.com/ so I can check.

0

I uploaded the whole configuration directory into _PyCharmCE2018.2.zip

AFAIK the only non-jetbrains plugin I have is PlantUML rendering, anyhow here is my current plugins list:

 

0

According to the log these are custom plugins: Makefile support (1.5), PlantUML integration (2.12.1)
Please try disabling them, restart and see if problem remains.

0

Disabling the "custom" plugins does not change anything.

Installation of new version **without** importing settings from previous version cures the problems.

I am happy as-is.

If You want to further pursue problem I am available to help.

0

Hm, that's odd.

Have you installed a new version into another directory?

Does it help in an old version if you remove a settings folder and start with defaults? (https://intellij-support.jetbrains.com/hc/en-us/articles/206544519)

0

Removing `.PyCharmCE2018.2` directory and restarting cures the problems.

It seems this is due to something I have in my old settings, brought over from version to version since `.PyCharmCE2017.1`.

You already have my "faulty" settings folder; if you want I can send my "clean" one.

0

Yes, I have tried it with your settings and there is no such problem. It could be that there is something in the environment that was "conflicting" with settings, it would explain why I couldn't reproduce.

Thank you for trying this out for me!

0

Please sign in to leave a comment.