Skip to content
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

Closed
wants to merge 6 commits into from
Closed

Fixed some typos and a docstring #10

wants to merge 6 commits into from

Conversation

demberto
Copy link

@demberto demberto commented Mar 2, 2022

No description provided.

Copy link
Owner

@afq984 afq984 left a 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.

cxxfilt/__init__.py Outdated Show resolved Hide resolved
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.
Copy link
Author

@demberto demberto left a 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

Copy link
Owner

@afq984 afq984 left a 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 and InternalError.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

@@ -1,117 +1,243 @@
from __future__ import annotations
Copy link
Owner

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
Copy link
Owner

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.

pass
# can be subclassed from FileNotFoundError?
# see https://stackoverflow.com/a/36077407
class LibraryNotFoundError(Error):
Copy link
Owner

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.

Copy link
Owner

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)


class InvalidNameError(Error):
"""Raised when a mangled name is an invalid
name under the GNU C++ ABI mangling rules."""
Copy link
Owner

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?

return repr(self.mangled_name)

def __repr__(self) -> str:
return f"{self.mangled_name} is an invalid name"
Copy link
Owner

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:
Copy link
Owner

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

else:
raise InternalError('Unkwon status code: {}'.format(status.value))
raise InternalError(ret)
Copy link
Owner

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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass can be removed


def __init__(self, choices: list[str]) -> None:
super().__init__()
self.choices = choices
Copy link
Owner

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.

Copy link
Author

@demberto demberto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...

@demberto demberto closed this Mar 7, 2022
@demberto demberto deleted the patch-1 branch March 7, 2022 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants