types-freezegun

1.1.10 · active · verified Thu Apr 09

Typing stubs for the `freezegun` library, enabling static type checking with tools like Mypy, PyCharm, and Pytype. This PEP 561 compliant package provides type hints for `freezegun`, which allows Python tests to manipulate time. It is maintained as part of the `typeshed` project and its updates generally follow `freezegun`'s release cycle for compatibility.

Warnings

Install

Imports

Quickstart

Demonstrates basic usage of `freezegun` with `freeze_time` as a decorator and context manager. `types-freezegun` provides the necessary type hints for static analysis of such code.

import datetime
from freezegun import freeze_time

# Example using the decorator
@freeze_time("2023-01-01")
def demonstrate_decorator_freeze():
    assert datetime.datetime.now() == datetime.datetime(2023, 1, 1)
    print(f"Current time (decorator): {datetime.datetime.now()}")

demonstrate_decorator_freeze()

# Example using the context manager
with freeze_time("2024-02-29 10:30:00"):
    assert datetime.date.today() == datetime.date(2024, 2, 29)
    assert datetime.datetime.now().hour == 10
    print(f"Current date (context manager): {datetime.date.today()}")

# To verify type checking, run a tool like Mypy (e.g., `mypy your_script.py`)
# with `types-freezegun` installed. It will ensure `freeze_time` and
# related objects are used with correct types.

view raw JSON →