Skip to content

Lazy imports in invalid places are not reported (Python 3.15, PEP 810) #5765

Todo

Description

@kinto0

Describe the Bug

Python 3.15 (PEP 810) raises SyntaxError for a lazy import in these places, but Pyrefly reports no error:

def f():
    lazy import json  # SyntaxError: lazy import not allowed inside functions

class C:
    lazy import json  # SyntaxError: lazy import not allowed inside classes

try:
    lazy import json  # SyntaxError: lazy import not allowed inside try/except blocks
except ImportError:
    pass

lazy from os import *  # SyntaxError: lazy from ... import * is not allowed
lazy from __future__ import annotations  # SyntaxError: lazy from __future__ import is not allowed

With python-version = "3.15", Pyrefly reports 0 errors. Ruff's semantic syntax checker detects these cases, but Pyrefly does not emit those errors.

Activity

  1. added
    py3.15
    on Nov 25, 2026
  2. self-assigned this
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

py3.15

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions