Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python PIL - Cannot find reference '[' in 'None'

Tags:

python

pycharm

I've been searching answers for this for the past hour and I'm feeling like any already asked question just barely misses my case.

I have been tinkering with the PIL library in Python, trying my first time to manipulate pixels, when all of a sudden a "Cannot find reference '[' in 'None'" Warning pops out. Naturally, I tried to read the IDE's warning and looked up simillar warnings online but only ended up with "missing imports" or "wrongly set interpreters".

This is the code in question:

from PIL import Image

with Image.open("./shoop_da_whoop.jpg") as img:
    pixel = img.load()
    width, height = img.size

    for x in range(0, width, 2):
        for y in range(0, height, 2):
            pixel[x, y] = (255, 0, 0)

    img.show()

The warning is right under the bracket: pixel*[*x, y] = (255, 0, 0). I have no clue whats going on and I will gladly try every advise.

I'm running Python 3.10 on the PyCharm version 2022.1

like image 277
Hawkeye Avatar asked Sep 16 '25 08:09

Hawkeye


1 Answers

PyCharm relies on typeshed stubs here and there is a mistake (or rather a missing type annotation) in them - load() method is declared to return None

class Image:
    ...
    def load(self) -> None: ...
like image 56
Pavel Karateev Avatar answered Sep 17 '25 21:09

Pavel Karateev