add mitigation section
This commit is contained in:
parent
16c020f674
commit
e6ce12334a
21
pep-0663.txt
21
pep-0663.txt
|
@ -41,8 +41,8 @@ Enums are becoming more common in the standard library; being able to recognize
|
|||
enum members by their ``repr()``, and having that ``repr()`` be easy to parse, is
|
||||
useful and can save time and effort in understanding and debugging code.
|
||||
|
||||
However, the enums with mixed-in data types (``IntEnum``, ``StrEnum``, and
|
||||
``IntFlag``) need to be more backwards compatible with the constants they are
|
||||
However, the enums with mixed-in data types (``IntEnum``, ``IntFlag``, and the new
|
||||
``StrEnum``) need to be more backwards compatible with the constants they are
|
||||
replacing -- specifically, ``str(replacement_enum_member) == str(original_constant)``
|
||||
should be true (and the same for ``format()``).
|
||||
|
||||
|
@ -156,12 +156,17 @@ Which will result in:
|
|||
| int drop-in | tools.LIGHT | -1 | -1 | tools.RED|tools.GREEN | 3 | 3 |
|
||||
+-------------+-----------------+------------+-----------------------+-----------------------+------------------------+-----------------------+
|
||||
|
||||
As you can see, ``repr()`` is primarily affected by whether the members are
|
||||
As can be seen, ``repr()`` is primarily affected by whether the members are
|
||||
global, while ``str()`` is affected by being global or by being a drop-in
|
||||
replacement, with the drop-in replacement status having a higher priority.
|
||||
Also, the basic ``repr()`` and ``str()`` have changed for flags as the old
|
||||
style was very clunky.
|
||||
|
||||
The ``repr()`` for Enum vs Flag are different, primarily because the Enum
|
||||
``repr()`` does not work well for flags. I like being able to tell whether
|
||||
an enum member is a Flag or an Enum based on the ``repr()`` alone, but am open
|
||||
to arguments for changing Enum's ``repr()`` to match Flag's.
|
||||
|
||||
|
||||
Backwards Compatibility
|
||||
=======================
|
||||
|
@ -176,6 +181,16 @@ prevent future breakage when ``IntEnum``, et al, are used to replace existing
|
|||
constants.
|
||||
|
||||
|
||||
Mitigation
|
||||
==========
|
||||
|
||||
Normal usage of enum members will not change: ``re.ASCII`` can still be used
|
||||
as ``re.ASCII`` and will still compare equal to ``256``. If one wants their
|
||||
own enums in their own code to remain the same they will need to write their
|
||||
own base Enum class and then write the appropriate``repr``, ``str()``, and
|
||||
``format()`` methods (or copy them from the 3.10 enum module).
|
||||
|
||||
|
||||
Copyright
|
||||
=========
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3.9
|
||||
"""Convert PEPs to (X)HTML - courtesy of /F
|
||||
|
||||
Usage: %(PROGRAM)s [options] [<peps> ...]
|
||||
|
|
Loading…
Reference in New Issue