gh-138978: Fully qualified name for abc classes exception. - #156683
gh-138978: Fully qualified name for abc classes exception.#156683skv0zsneg wants to merge 12 commits into
Conversation
|
|
||
| def check_program_exitcode(self, *args, check_stderr=True, **kwargs): | ||
| out, err = self.run_embedded_interpreter(*args, **kwargs) | ||
| self.assertEqual(out.rstrip(), 'ok! Py_RunMain() returned 123') |
There was a problem hiding this comment.
After adding changes to tests and typeobjec.c the strange error appear
AssertionError: 'Cmd click to launch VS Code Native REPL\nok! Py_RunMain() returned 123' != 'ok! Py_RunMain() returned 123'
- Cmd click to launch VS Code Native REPL
ok! Py_RunMain() returned 123
So, I changed it for checking exactly "ok!..." string.
There was a problem hiding this comment.
Could you check if it happens from CLI? My hunch is that it's VS Code artifact
There was a problem hiding this comment.
Wow, yes. From CLI test is not falling.
I do not clearly understand what this test (and others in Lib/test/test_embed.py) checking. Integrations with IDE's?
maurycy
left a comment
There was a problem hiding this comment.
I suspect that the C part can be a bit smaller, using %N
cpython/Objects/unicodeobject.c
Lines 3019 to 3049 in aad4288
| return NULL; | ||
| } | ||
|
|
||
| PyObject *type_name = _PyType_GetFullyQualifiedName(type, '.'); |
There was a problem hiding this comment.
Could you check if PyErr_Format already does this via %N?
There was a problem hiding this comment.
Yep! It works, and all test (locally) passes! Amazing, thank you!
There was a problem hiding this comment.
I wonder do docs have information about this cpython special string formats?
There was a problem hiding this comment.
| @@ -0,0 +1 @@ | |||
| Add fully qualified name for abc class initialization exception. | |||
There was a problem hiding this comment.
Maybe it should describe the user-visible change more, eg:
| Add fully qualified name for abc class initialization exception. | |
| The :exc:`TypeError` raised when instantiating an abstract class with unimplemented abstract methods now includes the fully qualified name of the class. |
There was a problem hiding this comment.
I love your version, thanks! I rewrite it like this
| with self.assertRaises(TypeError) as cm: | ||
| self.MyAbstractClass() | ||
|
|
||
| print(str(cm.exception)) |
There was a problem hiding this comment.
Left-over from debugging?
| print(str(cm.exception)) |
There was a problem hiding this comment.
Oh, how I missed this... Will remove
| abc.get_cache_token) | ||
| class TestAbstractClassErrorMessage(unittest.TestCase): | ||
|
|
||
| class MyAbstractClass(abc.ABC): |
There was a problem hiding this comment.
I think that abc_ABCMeta should be used here. My understanding is that test_factory creates a class twice - for C and Py variants - and hard-coded abc.ABC prevents the magic from happening :-)
| @@ -0,0 +1 @@ | |||
| The :exc:`TypeError` raised when instantiating an abstract class with unimplemented abstract methods now includes the fully qualified name of the class. | |||
There was a problem hiding this comment.
Nit:
| The :exc:`TypeError` raised when instantiating an abstract class with unimplemented abstract methods now includes the fully qualified name of the class. | |
| The :exc:`TypeError` raised when instantiating an abstract class with | |
| unimplemented abstract methods now includes the fully qualified name of the | |
| class. |
I'm sorry for this one, was typing from my phone. Typically we wrap around ~79 chars, as per https://devguide.python.org/documentation/markup/#use-of-whitespace
There was a problem hiding this comment.
No problem! Will know, thanks again!
TypeError#138978