close

How to deal with PyCharm’s “Expected type X, got Y instead”

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to deal with PyCharm’s “Expected type X, got Y instead”in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to deal with PyCharm’s “Expected type X, got Y instead”?

  1. How to deal with PyCharm's “Expected type X, got Y instead”?

    PyCharm determines from the type-hints of the source code that the arguments you pass are incorrect.

  2. deal with PyCharm's “Expected type X, got Y instead”

    PyCharm determines from the type-hints of the source code that the arguments you pass are incorrect.

Method 1

PyCharm determines from the type-hints of the source code that the arguments you pass are incorrect.


How to disable

Your question simplifies to one of figuring out how to disable this type checking. However, please be warned,

Switching off the inspection completely is not a good solution. Most of the time PyCharm gets it right and this provides useful feedback. If it’s getting it wrong, it’s best to raise a ticket with them to see if it can be fixed.

You can do that like this:

  1. Go to Settings/Preferences
  2. On the sidebar, click Inspections
  3. Expand the Python tab
  4. Scroll down to Type Checker and uncheck it

PyCharm should now stop issuing warnings about incorrect function arguments.

Method 2

Look at the specifications of the expit function. Nothing there says it’s permissible to provide a scalar argument – it calls for a numpy.ndarray. PyCharm is smart enough to tell you that any iterable (and hence a list) is acceptable, but this message isn’t a warning – it’s telling you your code as written does not meet the function’s specifications. As @JonClements points out in a comment, numpy‘s scalar broadcasting feature will allow this code to run, but PyCharm isn’t smart enough to deduce this.

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read