Closed as not planned
Description
mypy==1.15.0
[tool.mypy]
python_version = '3.12'
show_error_context = true
check_untyped_defs = true
ignore_missing_imports = true
warn_unused_ignores = true
warn_redundant_casts = true
show_error_code_links = true
warn_unreachable = true
Gist URL: https://gist.github.com/mypy-play/187d99115a24b12a7a58b437ae6127fb
For some reason, mypy displays the error "Statement is unreachable [unreachable]" for actual code that executes.
async_session: async_sessionmaker = async_sessionmaker(...)
class ProjectStatus(StrEnum):
NEW = 'new'
PENDING = 'pending'
FINISHED = 'finished'
class Project(Base):
__tablename__ = 'projects'
uid: Mapped[int] = mapped_column(primary_key=True)
status: Mapped[ProjectStatus] = mapped_column(
Enum(*list(ProjectStatus._value2member_map_.keys()), name='project_status_enum'),
server_default=ProjectStatus.NEW,
)
@pytest_asyncio.fixture
async def project_id() -> int:
...
async def update_status(project_id: int, status: ProjectStatus) -> None:
...
async def test_project_status(project_id: int) -> None:
async with async_session() as session:
tmp: Project | None = await session.get(Project, project_id)
assert tmp
project: Project = tmp
assert project.status == ProjectStatus.NEW # if comment this line, the "unreachable" error will disappear
for status in [ProjectStatus.PENDING, ProjectStatus.FINISHED]:
await update_status(project_id=project.uid, status=status)
await session.refresh(project)
assert project.status == status
if status == ProjectStatus.FINISHED:
print('the end') # error: Statement is unreachable [unreachable]