-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed some typos and a docstring #10
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix. Just a minor nit.
1. Added Google-style docstrings. 2. Exceptions are now how they should be. 3. Added `__all__` and `annotations`. 4. Replaced `.format()` with f-strings. I don't have a Linux/MacOS machine so you should check all this. Since I have changed the exception names, this should be a breaking release, you might rename them back to original names, but these names are more accurate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revamped version. Github confuses me like hell, I don't know if I did the right thing here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just take a look, some feedback:
- The code already uses single quotes. Don't change that (or make it its own PR).
- Exception names shouldn't be changed as existing code using them will break.
- Making the exceptions expose more info (such as
LibraryNotFoundError.choices
andInternalError.ret_code
) should be in another PR. But I'm not with the idea now. I don't think users' code can really use that extra information. - Still need to figure out the crash in CI
cxxfilt/__init__.py
Outdated
@@ -1,117 +1,243 @@ | |||
from __future__ import annotations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason this (PEP 563) is needed?
Adding this apparently also breaks the EOL'd python 3.6
|
||
class CharP(ctypes.c_char_p): | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I remember using its subclass actually cause some behavior change. Need to figure out what it was.
cxxfilt/__init__.py
Outdated
pass | ||
# can be subclassed from FileNotFoundError? | ||
# see https://stackoverflow.com/a/36077407 | ||
class LibraryNotFoundError(Error): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even the error names are currently inconsistent I would avoid changing them as doing so might break existing users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we cannot subclass from FileNotFoundError
(because it wasn't) as it changes observable behavior, such as
try:
with open(input) as file:
output = cxxfilt.demangle(file.read())
except FileNotFoundError:
print(input, 'not found')
except cxxfilt.InvalidName:
print(input, 'invalid')
else:
print(output)
cxxfilt/__init__.py
Outdated
|
||
class InvalidNameError(Error): | ||
"""Raised when a mangled name is an invalid | ||
name under the GNU C++ ABI mangling rules.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GNU C++ ABI
I'm not sure if the rules are GNU-defined. Can you provide some sources?
cxxfilt/__init__.py
Outdated
return repr(self.mangled_name) | ||
|
||
def __repr__(self) -> str: | ||
return f"{self.mangled_name} is an invalid name" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is redundant.
{'a': 3}['b']
says KeyError: 'b'
instead of KeyError: key b is missing
|
||
|
||
class DeferedErrorDemangler(BaseDemangler): | ||
def __init__(self, error: Exception) -> None: | ||
self._error = error | ||
|
||
def demangleb(self, mangled_name: bytes, external_only: bool = True) -> bytes: | ||
def demangleb(self, *_) -> bytes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will break existing code that calls using keyword arguments
cxxfilt/__init__.py
Outdated
else: | ||
raise InternalError('Unkwon status code: {}'.format(status.value)) | ||
raise InternalError(ret) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not move the status code handling into the InternalError
. Having them all here makes it obvious how each return value is handled.
Also, the error codes aren't intended to be exposed to the user.
|
||
class Error(Exception): | ||
"""Base class for all cxxfilt exceptions.""" | ||
|
||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pass
can be removed
cxxfilt/__init__.py
Outdated
|
||
def __init__(self, choices: list[str]) -> None: | ||
super().__init__() | ||
self.choices = choices |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not expose the choices list from LibraryNotFound in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...
No description provided.