Skip to content

Wrong return type on create_timer() #587

@Rasmus-S-Kristensen

Description

@Rasmus-S-Kristensen

🐛 Describe the bug
Type hint for return value of create_timer() is TaskBase, but that does not contain the cancel() function. Returning TimerTask seems more appropiate.

Current source:

def create_timer(self, fire_at: datetime.datetime) -> TaskBase:

Example code:

    expiration = context.current_utc_datetime + timedelta(seconds=20)
    timeout_task = context.create_timer(expiration)
    timeout_task.cancel()  # <-- Pylance shows error: "Cannot access attribute "cancel" for class "TaskBase""

🤔 Expected behavior
You should be able to call cancel()without linter/type checker errors.

Steps to reproduce
See above

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions