'Weird python syntax errors

So I have some code that gives three syntax errors but IT RUNS FINE, it almost like the syntax error are cosmetic or something. Its in a very large project that used googles cloud vision API, I might be giving more code then necessary to diagnose the issue but I think its pretty easy to parse and I figured it might be easy to see the whole method to know what is important

(the code that is erroring is basically just taken from google vision API examples but I did have to adapt it a bit so maybe that is the problem but it works so I am confused)

(it is also worth noting that the problem could be with visual studio code and not the code itself)

def detect_object_cord(path): """Localize objects in the local image.

def detect_object_cord(path): 
    """Localize objects in the local image.
    Args:
    path: The path to the local file.
    """

    client = vision.ImageAnnotatorClient(credentials=GOOGLE_APPLICATION_CREDENTIALS)

    f = 1


    with open(path, 'rb') as image_file: 
        content = image_file.read()
    image = vision.Image(content=content)#content=content

    objects = client.object_localization(image=image).localized_object_annotations

    print('Number of objects found: {}'.format(len(objects)))
    for object_ in objects:
        print('\n{} (confidence: {})'.format(object_.name, object_.score)) 
    
        for vertex in object_.bounding_poly.normalized_vertices:
        
            if FaceCount == 1:
                if f<= 4:
                    cordAryX.append(vertex.x  )
                    cordAryY.append(vertex.y  )

            if FaceCount == 2:
                if f<= 8 and f> 4:
                    cordAryX.append(vertex.x  )
                    cordAryY.append(vertex.y  )
                
            if FaceCount == 3:
                if f<= 12 and f > 8:
                    cordAryX.append(vertex.x  )
                    cordAryY.append(vertex.y  )
                
            if FaceCount == 4:
                if f<= 16 and f > 12:
                    cordAryX.append(vertex.x  )
                    cordAryY.append(vertex.y  )
                
            if FaceCount == 5:
                if f<= 20 and f > 16:
                    cordAryX.append(vertex.x  )
                    cordAryY.append(vertex.y  )
                
            if FaceCount == 6:
                if f<= 24 and f > 20:
                    cordAryX.append(vertex.x  )
                    cordAryY.append(vertex.y  )
                
            if FaceCount == 7:
                if f<= 28 and f > 24:
                    cordAryX.append(vertex.x  )
                    cordAryY.append(vertex.y  )
                
            if FaceCount == 8:
                if f<= 32 and f > 28:
                    cordAryX.append(vertex.x  )
                    cordAryY.append(vertex.y  )
                
            if FaceCount == 9:
                if f<= 36 and f > 32:
                    cordAryX.append(vertex.x  )
                    cordAryY.append(vertex.y  )
                
            if FaceCount == 10:
                if f<= 40 and f > 36:
                    cordAryX.append(vertex.x  )
                    cordAryY.append(vertex.y  )
               
            f = f+1

    print()
    print('user selection was: ' + FaceChoice)
    print('x: ', end='')
    print(cordAryX)
    print('y: ', end='')
    print(cordAryY)

the error for all three lines just says "SyntaxError: invalid syntax" and the lines that error are:

"with open(path, 'rb') as image_file:"

"content = image_file.read()"

"for object_ in objects:"

or at least those are the lines that the problems panel

Iv tried looking at it really hard and my brain can't see anything that is wrong. I can't see any out of place indents or spaces. and I don't see anything wrong in general. I have tried deleting and then re-typing out the lines by hand but to no use. As I said earlier the code runs and works as intended but the errors are making me crazy and I just want it to look perfect.



Solution 1:[1]

I figured it out, its listed in this post (SyntaxError : Invalid syntax jedi) and if you're getting the error(s) in visual studio code then basically just disable and then re-enable your packages. worked like a charm for me.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1