-
-
Notifications
You must be signed in to change notification settings - Fork 49
/
datacls.py
67 lines (56 loc) · 2.34 KB
/
datacls.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
# --------------------( LICENSE )--------------------
# Copyright (c) 2014-2021 Beartype authors.
# See "LICENSE" for further details.
'''
Project-wide **class globals** (i.e., global constants describing various
well-known types).
This private submodule is *not* intended for importation by downstream callers.
'''
# ....................{ IMPORTS }....................
from beartype._cave._cavefast import (
EllipsisType,
FunctionType,
FunctionOrMethodCType,
MethodBoundInstanceOrClassType,
ModuleType,
NoneType,
NotImplementedType,
)
# See the "beartype.cave" submodule for further commentary.
__all__ = ['STAR_IMPORTS_CONSIDERED_HARMFUL']
# ....................{ SETS }....................
TYPES_BUILTIN_FAKE = frozenset((
EllipsisType,
FunctionType,
FunctionOrMethodCType,
MethodBoundInstanceOrClassType,
ModuleType,
NoneType,
NotImplementedType,
))
'''
Frozen set of all **fake builtin types** (i.e., types that are *not* builtin
but which nonetheless erroneously masquerade as being builtin).
Like all non-builtin types, fake builtin types are globally inaccessible until
explicitly imported into the current lexical variable scope. Unlike all
non-builtin types, however, fake builtin types declare themselves to be
builtin. The standard example is the type of the ``None`` singleton: e.g.,
.. code-block:: python
>>> f'{type(None).__module__}.{type(None).__name__}'
'builtins.NoneType'
>>> NoneType
NameError: name 'NoneType' is not defined # <---- this is balls
These inconsistencies almost certainly constitute bugs in the CPython
interpreter itself, but it seems doubtful CPython developers would see it that
way and almost certain everyone else would defend these edge cases.
We're *not* dying on that lonely hill. We obey the Iron Law of Guido.
See Also
----------
:data:`beartype_test.a00_unit.data..TYPES_BUILTIN_FAKE`
Related test-time set. Whereas this runtime-specific set is efficiently
defined explicitly by listing all non-builtin builtin mimic types, that
test-specific set is inefficiently defined implicitly by introspecting the
:mod:`builtins` module. While less efficient, that test-specific set serves
as an essential sanity check on that runtime-specific set.
'''