{"id":2338,"library":"types-freezegun","title":"types-freezegun","description":"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.","status":"active","version":"1.1.10","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed/tree/master/stubs/freezegun","tags":["typing","stubs","type hints","freezegun","testing","datetime"],"install":[{"cmd":"pip install types-freezegun","lang":"bash","label":"Install `types-freezegun`"}],"dependencies":[{"reason":"Provides the runtime functionality for which these are type stubs.","package":"freezegun","optional":false}],"imports":[{"note":"This package provides type stubs for the 'freezegun' library. You import symbols directly from 'freezegun', and type checkers use these stubs for static analysis.","symbol":"freeze_time","correct":"from freezegun import freeze_time"}],"quickstart":{"code":"import datetime\nfrom freezegun import freeze_time\n\n# Example using the decorator\n@freeze_time(\"2023-01-01\")\ndef demonstrate_decorator_freeze():\n    assert datetime.datetime.now() == datetime.datetime(2023, 1, 1)\n    print(f\"Current time (decorator): {datetime.datetime.now()}\")\n\ndemonstrate_decorator_freeze()\n\n# Example using the context manager\nwith freeze_time(\"2024-02-29 10:30:00\"):\n    assert datetime.date.today() == datetime.date(2024, 2, 29)\n    assert datetime.datetime.now().hour == 10\n    print(f\"Current date (context manager): {datetime.date.today()}\")\n\n# To verify type checking, run a tool like Mypy (e.g., `mypy your_script.py`)\n# with `types-freezegun` installed. It will ensure `freeze_time` and\n# related objects are used with correct types.","lang":"python","description":"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."},"warnings":[{"fix":"If `freezegun >= 1.2.1`, uninstall `types-freezegun` (e.g., `pip uninstall types-freezegun`). If using an older `freezegun` version, ensure `types-freezegun` is compatible with it.","message":"`types-freezegun` is deprecated and should be uninstalled if you are using `freezegun` version 1.2.1 or newer. `freezegun` now includes its own type annotations directly within the package, rendering these external stubs redundant.","severity":"breaking","affected_versions":"< 1.2.1 of `freezegun`"},{"fix":"Always check for compatibility, especially if type checking errors appear after updating one of the packages. The most reliable fix is to migrate to `freezegun >= 1.2.1` and uninstall `types-freezegun`.","message":"Mismatched versions of `freezegun` and `types-freezegun` can lead to incorrect or incomplete type checking results. While `typeshed` aims for compatibility, newer features or breaking changes in `freezegun` might not be immediately reflected in older `types-freezegun` stubs, or vice-versa.","severity":"gotcha","affected_versions":"All versions where `types-freezegun` is used with `freezegun`."},{"fix":"Avoid strict type equality checks (`type(obj) is expected_type`) with objects manipulated by `freezegun`. Prefer `isinstance(obj, expected_type)` for broader compatibility. Review any third-party library integrations that might perform such strict checks.","message":"When `freezegun` is active, `datetime.datetime.now()` returns `FakeDatetime` objects, which inherit from `datetime.datetime` but are not strictly identical. Libraries or code performing strict type checks (e.g., `type(obj) is datetime.datetime`) rather than `isinstance(obj, datetime.datetime)` might encounter runtime errors or unexpected behavior, even if type checking passes.","severity":"gotcha","affected_versions":"All versions of `freezegun` and `types-freezegun`."}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}