ruff: F401 (unused import) false positive

Hello, I have an import that is used in typing and is getting removed by ruff (flake8 detects it as unused as well) here is the example:

from typing import Optional
import datetime # <--- gets removed by ruff
import pydantic

class SomeClass(pydantic.BaseModel):
    datetime: Optional[datetime.datetime]

for now, i’m adding the comment # noqa: F401 to keep the import.

ruff version 0.0.195

Thank you for this project 🤩

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 15 (11 by maintainers)

Most upvoted comments

Came across this today - if it helps here is where the from __future__ import annotations issue was raised in pyflakes

Here’s an minimal reproducible example:

from __future__ import annotations

import datetime
from typing import Optional

class SomeClass:
    datetime: Optional[datetime.datetime]

Should be out soon, maybe today? We’ll see! 😃

Oh, yeah, it could be __future__.