Skip to content

concat of types Iterable[Any] cause Pyright to think subsequent code is unreachable because of recent stubs change #888

Closed
@torext

Description

@torext

Describe the bug
In the following code the last line is wrongly considered to be unreachable by Pyright:

from typing import Any

import pandas as pd


def generate_series() -> Any:
    return pd.Series([1, 2, 3])


df = pd.concat({k: generate_series() for k in range(10)}, axis=1)

print("Unreachable?!")

This is caused by the recent change #858 adding a stub returning Never. This is presumably a misuse of Never or the stub as a whole should be moved to the very end so that concat on types Iterable[Any] can first match a stub with valid return.

To Reproduce
See microsoft/pylance-release#5631 and microsoft/pylance-release#5630 for issues reported on the Pylance repo.

Please complete the following information:

  • OS: Linux
  • OS Version 5.15.0-46-generic
  • Python 3.11.6
  • Pylance v2024.3.1
  • version of installed pandas-stubs: the one shipped with above Pylance version

Metadata

Metadata

Assignees

Labels

ReshapingConcat, Merge/Join, Stack/Unstack, Explode

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions