Skip to content

Commit f458c4d

Browse files
committed
Raise a better error when contexts are pickled.
1 parent a47b52a commit f458c4d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ v2.0.0
88

99
Unreleased
1010
------------------
11+
Added
1112
- Added some keyboard functions:
1213
- `tcod.event.get_keyboard_state`
1314
- `tcod.event.get_modifier_state`
1415
- `tcod.event.key_from_scancode`
1516
- `tcod.event.scancode_from_key`
1617
- `tcod.event.get_key_name`
1718

19+
Fixed
20+
- Contexts now give a more useful error when pickled.
21+
1822
12.2.0 - 2021-04-09
1923
-------------------
2024
Added

tcod/context.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@
4848
.. versionadded:: 11.12
4949
""" # noqa: E501
5050
import os
51+
import pickle
5152
import sys
5253
from typing import Any, Iterable, List, Optional, Tuple
5354

54-
from typing_extensions import Literal
55+
from typing_extensions import Literal, NoReturn
5556

5657
import tcod
5758
import tcod.event
@@ -366,6 +367,12 @@ def toggle_fullscreen(context: tcod.context.Context) -> None:
366367
''' # noqa: E501
367368
return lib.TCOD_context_get_sdl_window(self._context_p)
368369

370+
def __reduce__(self) -> NoReturn:
371+
"""Contexts can not be pickled, so this class will raise
372+
:class:`pickle.PicklingError`.
373+
"""
374+
raise pickle.PicklingError("Python-tcod contexts can not be pickled.")
375+
369376

370377
@ffi.def_extern() # type: ignore
371378
def _pycall_cli_output(catch_reference: Any, output: Any) -> None:

0 commit comments

Comments
 (0)