Skip to content

Bug: TypeError in Job.__repr__ when unit is None #6

@srics96

Description

@srics96

Bug Description

When a Job object is created but not yet fully configured (e.g., schedule.every(10).seconds without calling .do()), accessing repr() or printing the job crashes with a TypeError because self.unit is None.

Steps to Reproduce

import schedule
job = schedule.every(10)
# unit is not yet set
print(job)  # TypeError: argument of type 'NoneType' is not iterable

The crash happens in Job.__repr__ where it checks if self.unit[0] != "s" — this fails when self.unit is None.

Fix

Add a guard in __repr__ to handle None unit:

def __repr__(self):
    ...
    if self.unit is not None and self.unit[0] != "s":
        ...

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    fix-meGhost Ship will auto-fix this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions