Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
4a12a178
Commit
4a12a178
authored
Sep 11, 2019
by
Daniel Andrade
Committed by
Stéphane Wirtel
Sep 11, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-34331: Fix incorrectly pluralized abstract class error message. (GH-8670)
parent
19f6940c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
1 deletion
+27
-1
Lib/test/test_abc.py
Lib/test/test_abc.py
+19
-0
Misc/NEWS.d/next/C API/2018-08-04-00-59-44.bpo-34331.iaUkmU.rst
...EWS.d/next/C API/2018-08-04-00-59-44.bpo-34331.iaUkmU.rst
+2
-0
Objects/typeobject.c
Objects/typeobject.c
+6
-1
No files found.
Lib/test/test_abc.py
View file @
4a12a178
...
...
@@ -149,6 +149,25 @@ def test_factory(abc_ABCMeta, abc_get_cache_token):
self
.
assertEqual
(
D
.
foo
(),
4
)
self
.
assertEqual
(
D
().
foo
(),
4
)
def
test_object_new_with_one_abstractmethod
(
self
):
class
C
(
metaclass
=
abc_ABCMeta
):
@
abc
.
abstractmethod
def
method_one
(
self
):
pass
msg
=
r"class C with abstract method method_one"
self
.
assertRaisesRegex
(
TypeError
,
msg
,
C
)
def
test_object_new_with_many_abstractmethods
(
self
):
class
C
(
metaclass
=
abc_ABCMeta
):
@
abc
.
abstractmethod
def
method_one
(
self
):
pass
@
abc
.
abstractmethod
def
method_two
(
self
):
pass
msg
=
r"class C with abstract methods method_one, method_two"
self
.
assertRaisesRegex
(
TypeError
,
msg
,
C
)
def
test_abstractmethod_integration
(
self
):
for
abstractthing
in
[
abc
.
abstractmethod
,
abc
.
abstractproperty
,
abc
.
abstractclassmethod
,
...
...
Misc/NEWS.d/next/C API/2018-08-04-00-59-44.bpo-34331.iaUkmU.rst
0 → 100644
View file @
4a12a178
Use singular/plural noun in error message when instantiating an abstract
class with non-overriden abstract method(s).
Objects/typeobject.c
View file @
4a12a178
...
...
@@ -3753,6 +3753,7 @@ object_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
PyObject
*
joined
;
PyObject
*
comma
;
_Py_static_string
(
comma_id
,
", "
);
Py_ssize_t
method_count
;
/* Compute ", ".join(sorted(type.__abstractmethods__))
into joined. */
...
...
@@ -3773,14 +3774,18 @@ object_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return
NULL
;
}
joined
=
PyUnicode_Join
(
comma
,
sorted_methods
);
method_count
=
PyObject_Length
(
sorted_methods
);
Py_DECREF
(
sorted_methods
);
if
(
joined
==
NULL
)
return
NULL
;
if
(
method_count
==
-
1
)
return
NULL
;
PyErr_Format
(
PyExc_TypeError
,
"Can't instantiate abstract class %s "
"with abstract methods %U"
,
"with abstract method
%
s %U"
,
type
->
tp_name
,
method_count
>
1
?
"s"
:
""
,
joined
);
Py_DECREF
(
joined
);
return
NULL
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment