Skip to content

StopIteration error raised on starred assignment #546

@dhirschfeld

Description

@dhirschfeld

Things to check first

  • I have searched the existing issues and didn't find my bug already reported there

  • I have checked that my bug is still present in the latest release

Typeguard version

4.5.0

Python version

3.12

What happened?

On the latest 4.5.0 the below code raised a StopIteration error:

typegurad_bug.py

from typeguard import typechecked


@typechecked
def write_table(table_name: str):
    # This line causes StopIteration in typeguard 4.5.0
    *schema, table_name = table_name.rsplit(".", maxsplit=1)
    return schema, table_name


# This will fail:
write_table("schema.table_name")
❯ python typeguard_bug.py
Traceback (most recent call last):
  File "~/code/sandbox/typeguard_bug.py", line 12, in <module>
    write_table("schema.table_name")
  File "~/code/sandbox/typeguard_bug.py", line 7, in write_table
    *schema, table_name = table_name.rsplit(".", maxsplit=1)
  File "~/code/sandbox/.pixi/envs/py312/lib/python3.12/site-packages/typeguard/_functions.py", line 336, in check_variable_assignment
    next_value = next(iterator)
                 ^^^^^^^^^^^^^^
StopIteration

This doesn't happen on 4.4.4.

I've pinned the version for now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions