Skip to content

Incorrect error message when using ; #142118

@GlebSBrykin

Description

@GlebSBrykin

Bug report

Bug description:

Some syntax errors (I was able to find at least 2 cases) lead to incorrect messages that completely make it impossible to understand what exactly is wrong. In this case, the error is always thrown on the first import with an alias via as.

The first case is written twice ;:

import torch;
import torch.nn as nn;

def foo(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
    d = torch.sqrt(x ** 2 + y ** 2);;
    return d;
Image

The second case is the re-specified def when declaring the function.:

import torch;
import torch.nn as nn;

def foo(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
    d = torch.sqrt(x ** 2 + y ** 2);
    return d;

def def bar():
    pass;
Image

Deleting ; after importing with as returns the correct error message.

Image

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThe issue will be closed if no feedback is providedstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions