Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit28a2ccf

Browse files
authored
[Enum] Remove automatic docstring generation (GH-94188)
1 parent9a95fa9 commit28a2ccf

File tree

2 files changed

+4
-267
lines changed

2 files changed

+4
-267
lines changed

‎Lib/enum.py‎

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -536,111 +536,6 @@ def __new__(metacls, cls, bases, classdict, *, boundary=None, _simple=False, **k
536536
# update classdict with any changes made by __init_subclass__
537537
classdict.update(enum_class.__dict__)
538538
#
539-
# create a default docstring if one has not been provided
540-
ifenum_class.__doc__isNone:
541-
ifnotmember_namesornotlist(enum_class):
542-
enum_class.__doc__=classdict['__doc__']=_dedent("""\
543-
Create a collection of name/value pairs.
544-
545-
Example enumeration:
546-
547-
>>> class Color(Enum):
548-
... RED = 1
549-
... BLUE = 2
550-
... GREEN = 3
551-
552-
Access them by:
553-
554-
- attribute access::
555-
556-
>>> Color.RED
557-
<Color.RED: 1>
558-
559-
- value lookup:
560-
561-
>>> Color(1)
562-
<Color.RED: 1>
563-
564-
- name lookup:
565-
566-
>>> Color['RED']
567-
<Color.RED: 1>
568-
569-
Enumerations can be iterated over, and know how many members they have:
570-
571-
>>> len(Color)
572-
3
573-
574-
>>> list(Color)
575-
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]
576-
577-
Methods can be added to enumerations, and members can have their own
578-
attributes -- see the documentation for details.
579-
""")
580-
else:
581-
member=list(enum_class)[0]
582-
enum_length=len(enum_class)
583-
cls_name=enum_class.__name__
584-
ifenum_length==1:
585-
list_line='list(%s)'%cls_name
586-
list_repr='[<%s.%s: %r>]'% (cls_name,member.name,member.value)
587-
elifenum_length==2:
588-
member2=list(enum_class)[1]
589-
list_line='list(%s)'%cls_name
590-
list_repr='[<%s.%s: %r>, <%s.%s: %r>]'% (
591-
cls_name,member.name,member.value,
592-
cls_name,member2.name,member2.value,
593-
)
594-
else:
595-
member2=list(enum_class)[1]
596-
member3=list(enum_class)[2]
597-
list_line='list(%s)%s'% (cls_name, ('','[:3]')[enum_length>3])
598-
list_repr='[<%s.%s: %r>, <%s.%s: %r>, <%s.%s: %r>]'% (
599-
cls_name,member.name,member.value,
600-
cls_name,member2.name,member2.value,
601-
cls_name,member3.name,member3.value,
602-
)
603-
enum_class.__doc__=classdict['__doc__']=_dedent("""\
604-
A collection of name/value pairs.
605-
606-
Access them by:
607-
608-
- attribute access::
609-
610-
>>> %s.%s
611-
<%s.%s: %r>
612-
613-
- value lookup:
614-
615-
>>> %s(%r)
616-
<%s.%s: %r>
617-
618-
- name lookup:
619-
620-
>>> %s[%r]
621-
<%s.%s: %r>
622-
623-
Enumerations can be iterated over, and know how many members they have:
624-
625-
>>> len(%s)
626-
%r
627-
628-
>>> %s
629-
%s
630-
631-
Methods can be added to enumerations, and members can have their own
632-
attributes -- see the documentation for details.
633-
"""
634-
% (cls_name,member.name,
635-
cls_name,member.name,member.value,
636-
cls_name,member.value,
637-
cls_name,member.name,member.value,
638-
cls_name,member.name,
639-
cls_name,member.name,member.value,
640-
cls_name,enum_length,
641-
list_line,list_repr,
642-
))
643-
#
644539
# double check that repr and friends are not the mixin's or various
645540
# things break (such as pickle)
646541
# however, if the method is defined in the Enum itself, don't replace

‎Lib/test/test_enum.py‎

Lines changed: 4 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -4054,36 +4054,6 @@ class TestEnumTypeSubclassing(unittest.TestCase):
40544054
class Color(enum.Enum)
40554055
| Color(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
40564056
|\x20\x20
4057-
| A collection of name/value pairs.
4058-
|\x20\x20
4059-
| Access them by:
4060-
|\x20\x20
4061-
| - attribute access::
4062-
|\x20\x20
4063-
| >>> Color.CYAN
4064-
| <Color.CYAN: 1>
4065-
|\x20\x20
4066-
| - value lookup:
4067-
|\x20\x20
4068-
| >>> Color(1)
4069-
| <Color.CYAN: 1>
4070-
|\x20\x20
4071-
| - name lookup:
4072-
|\x20\x20
4073-
| >>> Color['CYAN']
4074-
| <Color.CYAN: 1>
4075-
|\x20\x20
4076-
| Enumerations can be iterated over, and know how many members they have:
4077-
|\x20\x20
4078-
| >>> len(Color)
4079-
| 3
4080-
|\x20\x20
4081-
| >>> list(Color)
4082-
| [<Color.CYAN: 1>, <Color.MAGENTA: 2>, <Color.YELLOW: 3>]
4083-
|\x20\x20
4084-
| Methods can be added to enumerations, and members can have their own
4085-
| attributes -- see the documentation for details.
4086-
|\x20\x20
40874057
| Method resolution order:
40884058
| Color
40894059
| enum.Enum
@@ -4329,157 +4299,29 @@ def test__all__(self):
43294299
deftest_doc_1(self):
43304300
classSingle(Enum):
43314301
ONE=1
4332-
self.assertEqual(
4333-
Single.__doc__,
4334-
dedent("""\
4335-
A collection of name/value pairs.
4336-
4337-
Access them by:
4338-
4339-
- attribute access::
4340-
4341-
>>> Single.ONE
4342-
<Single.ONE: 1>
4343-
4344-
- value lookup:
4345-
4346-
>>> Single(1)
4347-
<Single.ONE: 1>
4348-
4349-
- name lookup:
4350-
4351-
>>> Single['ONE']
4352-
<Single.ONE: 1>
4353-
4354-
Enumerations can be iterated over, and know how many members they have:
4355-
4356-
>>> len(Single)
4357-
1
4358-
4359-
>>> list(Single)
4360-
[<Single.ONE: 1>]
4361-
4362-
Methods can be added to enumerations, and members can have their own
4363-
attributes -- see the documentation for details.
4364-
"""))
4302+
self.assertEqual(Single.__doc__,None)
43654303

43664304
deftest_doc_2(self):
43674305
classDouble(Enum):
43684306
ONE=1
43694307
TWO=2
4370-
self.assertEqual(
4371-
Double.__doc__,
4372-
dedent("""\
4373-
A collection of name/value pairs.
4374-
4375-
Access them by:
4376-
4377-
- attribute access::
4378-
4379-
>>> Double.ONE
4380-
<Double.ONE: 1>
4381-
4382-
- value lookup:
4383-
4384-
>>> Double(1)
4385-
<Double.ONE: 1>
4386-
4387-
- name lookup:
4388-
4389-
>>> Double['ONE']
4390-
<Double.ONE: 1>
4391-
4392-
Enumerations can be iterated over, and know how many members they have:
4393-
4394-
>>> len(Double)
4395-
2
4396-
4397-
>>> list(Double)
4398-
[<Double.ONE: 1>, <Double.TWO: 2>]
4399-
4400-
Methods can be added to enumerations, and members can have their own
4401-
attributes -- see the documentation for details.
4402-
"""))
4308+
self.assertEqual(Double.__doc__,None)
44034309

44044310

44054311
deftest_doc_1(self):
44064312
classTriple(Enum):
44074313
ONE=1
44084314
TWO=2
44094315
THREE=3
4410-
self.assertEqual(
4411-
Triple.__doc__,
4412-
dedent("""\
4413-
A collection of name/value pairs.
4414-
4415-
Access them by:
4416-
4417-
- attribute access::
4418-
4419-
>>> Triple.ONE
4420-
<Triple.ONE: 1>
4421-
4422-
- value lookup:
4423-
4424-
>>> Triple(1)
4425-
<Triple.ONE: 1>
4426-
4427-
- name lookup:
4428-
4429-
>>> Triple['ONE']
4430-
<Triple.ONE: 1>
4431-
4432-
Enumerations can be iterated over, and know how many members they have:
4433-
4434-
>>> len(Triple)
4435-
3
4436-
4437-
>>> list(Triple)
4438-
[<Triple.ONE: 1>, <Triple.TWO: 2>, <Triple.THREE: 3>]
4439-
4440-
Methods can be added to enumerations, and members can have their own
4441-
attributes -- see the documentation for details.
4442-
"""))
4316+
self.assertEqual(Triple.__doc__,None)
44434317

44444318
deftest_doc_1(self):
44454319
classQuadruple(Enum):
44464320
ONE=1
44474321
TWO=2
44484322
THREE=3
44494323
FOUR=4
4450-
self.assertEqual(
4451-
Quadruple.__doc__,
4452-
dedent("""\
4453-
A collection of name/value pairs.
4454-
4455-
Access them by:
4456-
4457-
- attribute access::
4458-
4459-
>>> Quadruple.ONE
4460-
<Quadruple.ONE: 1>
4461-
4462-
- value lookup:
4463-
4464-
>>> Quadruple(1)
4465-
<Quadruple.ONE: 1>
4466-
4467-
- name lookup:
4468-
4469-
>>> Quadruple['ONE']
4470-
<Quadruple.ONE: 1>
4471-
4472-
Enumerations can be iterated over, and know how many members they have:
4473-
4474-
>>> len(Quadruple)
4475-
4
4476-
4477-
>>> list(Quadruple)[:3]
4478-
[<Quadruple.ONE: 1>, <Quadruple.TWO: 2>, <Quadruple.THREE: 3>]
4479-
4480-
Methods can be added to enumerations, and members can have their own
4481-
attributes -- see the documentation for details.
4482-
"""))
4324+
self.assertEqual(Quadruple.__doc__,None)
44834325

44844326

44854327
# These are unordered here on purpose to ensure that declaration order

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp