Skip to content

Commit 6efdacf

Browse files
committed
Remove the raw color name/value mappings.
It was never a good idea to use them directly, so they've been removed from the public API. Code which accessed them directly should use the normalizing conversion functions instead.
1 parent b014e65 commit 6efdacf

File tree

4 files changed

+16
-114
lines changed

4 files changed

+16
-114
lines changed

docs/changelog.rst

+7-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ subsequent release in the same month would be 25.1.1; a release the following
2020
month (February) would be 25.2.0.
2121

2222
The CalVer system was adopted for this library in 2024, and the first release
23-
to use a CalVer version number was 24.5.0.
23+
to use a CalVer version number was 24.6.0.
2424

2525

2626
API stability and deprecations
@@ -50,13 +50,13 @@ The API stability/deprecation policy for this library is as follows:
5050
case.
5151

5252
* This policy is in effect as of the adoption of CalVer versioning, with
53-
version 24.5.0 of this library.
53+
version 24.6.0 of this library.
5454

5555

5656
Releases under CalVer
5757
---------------------
5858

59-
Version 24.5.0
59+
Version 24.6.0
6060
~~~~~~~~~~~~~~
6161

6262
*Not yet released*
@@ -75,6 +75,10 @@ Version 24.5.0
7575

7676
* Adopted `CalVer versioning <https://calver.org>`_.
7777

78+
* The raw mappings of color names/values are no longer publicly exposed; use
79+
the appropriate normalizing conversion functions instead of accessing the
80+
mappings directly.
81+
7882

7983
Releases not under CalVer
8084
-------------------------

docs/contents.rst

+2-82
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,11 @@ defined, and used throughout this module:
6666
.. autodata:: IntTuple
6767
.. autodata:: PercentTuple
6868

69-
Constants
70-
---------
71-
72-
Several sets of constants are provided in ``webcolors``, for use when
73-
converting or identifying colors or specifications.
7469

7570
.. _spec-constants:
7671

77-
Specification identifiers
78-
~~~~~~~~~~~~~~~~~~~~~~~~~~
72+
Constants
73+
---------
7974

8075
The following constants are available for indicating the specification from
8176
which to draw color name choices, in functions which can work with multiple
@@ -98,81 +93,6 @@ specifications.
9893
Represents the HTML 4 specification. Value is ``"html4"``.
9994

10095

101-
.. _mapping-constants:
102-
103-
Color mappings
104-
~~~~~~~~~~~~~~
105-
106-
The following constants are available for direct use in mapping from color
107-
names to values, although it is strongly recommended to use one of the
108-
normalizing conversion functions instead.
109-
110-
111-
Mappings from names to hexadecimal values
112-
+++++++++++++++++++++++++++++++++++++++++
113-
114-
.. data:: HTML4_NAMES_TO_HEX
115-
116-
A :class:`dict` whose keys are the normalized names of the sixteen named
117-
HTML 4 colors, and whose values are the normalized hexadecimal values of
118-
those colors.
119-
120-
.. data:: CSS2_NAMES_TO_HEX
121-
122-
An alias for :data:`~webcolors.HTML4_NAMES_TO_HEX`, as CSS2 defined the same
123-
set of colors.
124-
125-
.. data:: CSS21_NAMES_TO_HEX
126-
127-
A :class:`dict` whose keys are the normalized names of the seventeen named
128-
CSS2.1 colors, and whose values are the normalized hexadecimal values of
129-
those colors (sixteen of these are identical to HTML 4 and CSS2; the
130-
seventeenth color is ``"orange"``, added in CSS2.1).
131-
132-
.. data:: CSS3_NAMES_TO_HEX
133-
134-
A :class:`dict` whose keys are the normalized names of the 147 named CSS3
135-
colors, and whose values are the normalized hexadecimal values of those
136-
colors. These colors are also identical to the 147 named colors of SVG.
137-
138-
139-
Mappings from hexadecimal values to names
140-
+++++++++++++++++++++++++++++++++++++++++
141-
142-
.. data:: HTML4_HEX_TO_NAMES
143-
144-
A :class:`dict` whose keys are the normalized hexadecimal values of the
145-
sixteen named HTML 4 colors, and whose values are the corresponding
146-
normalized names.
147-
148-
.. data:: CSS2_HEX_TO_NAMES
149-
150-
An alias for :data:`~webcolors.HTML4_HEX_TO_NAMES`, as CSS2 defined the same
151-
set of colors.
152-
153-
.. data:: CSS21_HEX_TO_NAMES
154-
155-
A :class:`dict` whose keys are the normalized hexadecimal values of the
156-
seventeen named CSS2.1 colors, and whose values are the corresponding
157-
normalized names (sixteen of these are identical to HTML 4 and CSS2; the
158-
seventeenth color is ``"orange"``, added in CSS2.1).
159-
160-
.. data:: CSS3_HEX_TO_NAMES
161-
162-
A :class:`dict` whose keys are the normalized hexadecimal values of the 147
163-
named CSS3 colors, and whose values are the corresponding normalized
164-
names. These colors are also identical to the 147 named colors of SVG.
165-
166-
.. note:: **Spelling variants**
167-
168-
Some values representing named gray colors can map to either of two names
169-
in CSS3, because it supports both ``"gray"`` and ``"grey"`` spelling
170-
variants for those colors. This mapping will always return the variant
171-
spelled ``"gray"`` (such as ``"lightgray"`` instead of
172-
``"lightgrey"``). See :ref:`the documentation on name conventions
173-
<color-name-conventions>` for details.
174-
175-
17696
Normalization functions
17797
-----------------------
17898

src/webcolors/__init__.py

+6-28
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
"""
2-
Utility functions for working with the color names and color value
3-
formats defined by the HTML and CSS specifications for use in
4-
documents on the web.
2+
Functions for working with the color names and color value formats defined by the
3+
HTML and CSS specifications for use in documents on the web.
54
6-
See documentation (in docs/ directory of source distribution) for
7-
details of the supported formats, conventions and conversions.
5+
See documentation (in docs/ directory of source distribution) for details of the
6+
supported formats, conventions and conversions.
87
98
"""
109

@@ -24,20 +23,7 @@
2423
rgb_to_name,
2524
rgb_to_rgb_percent,
2625
)
27-
from ._definitions import (
28-
CSS2,
29-
CSS2_HEX_TO_NAMES,
30-
CSS2_NAMES_TO_HEX,
31-
CSS3,
32-
CSS3_HEX_TO_NAMES,
33-
CSS3_NAMES_TO_HEX,
34-
CSS21,
35-
CSS21_HEX_TO_NAMES,
36-
CSS21_NAMES_TO_HEX,
37-
HTML4,
38-
HTML4_HEX_TO_NAMES,
39-
HTML4_NAMES_TO_HEX,
40-
)
26+
from ._definitions import CSS2, CSS3, CSS21, HTML4
4127
from ._html5 import (
4228
html5_parse_legacy_color,
4329
html5_parse_simple_color,
@@ -50,21 +36,13 @@
5036
)
5137
from ._types import HTML5SimpleColor, IntegerRGB, IntTuple, PercentRGB, PercentTuple
5238

53-
__version__ = "24.5.0a1"
39+
__version__ = "24.6.0a1"
5440

5541
__all__ = [
5642
"HTML4",
5743
"CSS2",
5844
"CSS21",
5945
"CSS3",
60-
"HTML4_NAMES_TO_HEX",
61-
"HTML4_HEX_TO_NAMES",
62-
"CSS2_NAMES_TO_HEX",
63-
"CSS2_HEX_TO_NAMES",
64-
"CSS21_HEX_TO_NAMES",
65-
"CSS21_NAMES_TO_HEX",
66-
"CSS3_HEX_TO_NAMES",
67-
"CSS3_NAMES_TO_HEX",
6846
"name_to_hex",
6947
"name_to_rgb",
7048
"name_to_rgb_percent",

tests/test_html5.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def test_parse_legacy_color_names(self):
8888
Test the HTML5 legacy color parsing of SVG/CSS3 color names.
8989
9090
"""
91-
for name in webcolors.CSS3_NAMES_TO_HEX:
91+
for name in webcolors._definitions.CSS3_NAMES_TO_HEX:
9292
parsed = webcolors.html5_parse_legacy_color(name)
9393
assert parsed == webcolors.name_to_rgb(name)
9494

0 commit comments

Comments
 (0)