gleplot 6.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
gleplot/_warn.py ADDED
@@ -0,0 +1,45 @@
1
+ """Warnings attributed to the user's line rather than to gleplot's."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import sys
6
+ import warnings
7
+ from types import FrameType
8
+ from typing import Any, Iterable, Optional, Type, Union
9
+
10
+
11
+ def warn_external(
12
+ message: Union[str, Warning], category: Type[Warning] = UserWarning
13
+ ) -> None:
14
+ """``warnings.warn`` at the first calling frame outside the gleplot package.
15
+
16
+ A fixed ``stacklevel`` is right for one call path only. The same warning is
17
+ reached from ``Figure.savefig``, ``glp.savefig`` and ``Figure.view`` at
18
+ different depths, and every ``glp.*`` function adds a frame in front of the
19
+ ``Axes`` method it forwards to.
20
+ """
21
+ frame: Optional[FrameType] = sys._getframe(1)
22
+ stacklevel = 2
23
+ while frame is not None:
24
+ module = frame.f_globals.get("__name__", "")
25
+ if module != "gleplot" and not module.startswith("gleplot."):
26
+ break
27
+ frame = frame.f_back
28
+ stacklevel += 1
29
+ warnings.warn(message, category, stacklevel=stacklevel)
30
+
31
+
32
+ def warn_unsupported_keywords(
33
+ caller: str, names: Iterable[Any], hint: str = ""
34
+ ) -> None:
35
+ """One warning listing the keyword ``names`` that ``caller()`` ignores.
36
+
37
+ The shared message for keywords a public call accepts but cannot honour.
38
+ The caller first takes out what it handles, matplotlib's short aliases
39
+ included; nothing is said when ``names`` is empty. ``hint``, a sentence
40
+ saying what the call does take, follows the list.
41
+ """
42
+ listed = ", ".join(sorted(str(name) for name in names))
43
+ if listed:
44
+ message = f"{caller}() ignores unsupported keyword(s): {listed}."
45
+ warn_external(f"{message} {hint}" if hint else message)