Repository: mandiant/capa
File: capa/features/extractors/dnfile/types.py (Python)

Code before:
# Copyright (C) 2023 Mandiant, Inc. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
# You may obtain a copy of the License at: [package root]/LICENSE.txt
# Unless required by applicable law or agreed to in writing, software distributed under the License
#  is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.

from typing import Tuple, Optional

class DnType:
    def __init__(self, token: int, class_: Tuple[str, ...], namespace: str = "", member: str = "", access: Optional[str] = None):
        self.token: int = token
        self.access: Optional[str] = access
        self.namespace: str = namespace
        self.class_: Tuple[str, ...] = class_

        if member == ".ctor":
            member = "ctor"
        if member == ".cctor":
            member = "cctor"

        self.member: str = member

    def __hash__(self):
        return hash((self.token, self.access, self.namespace, self.class_, self.member))

    def __eq__(self, other):
        return (
            self.token == other.token
            and self.access == other.access
            and self.namespace == other.namespace
            and self.class_ == other.class_
            and self.member == other.member

Review comment (bug):
@bkojusner there is a linting error thrown by `isort`:

```
isort....................................................................Failed
- hook id: isort
- files were modified by this hook

Fixing /home/runner/work/capa/capa/capa/features/extractors/dnfile/types.py
Skipped 2 files

All changes made by hooks:
diff --git a/capa/features/extractors/dnfile/types.py b/capa/features/extractors/dnfile/types.py
index 44208ba..fab3[19](https://github.com/mandiant/capa/actions/runs/7414374552/job/20175310940?pr=1913#step:6:20)6 100644
--- a/capa/features/extractors/dnfile/types.py
+++ b/capa/features/extractors/dnfile/types.py
@@ -8,6 +8,7 @@
 
 from typing import Tuple, Optional
 
+
 class DnType:
     def __init__(self, token: int, class_: Tuple[str, ...], namespace: str = "", member: str = "", access: Optional[str] = None):
         self.token: int = token
```

Code after:
# Copyright (C) 2023 Mandiant, Inc. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
# You may obtain a copy of the License at: [package root]/LICENSE.txt
# Unless required by applicable law or agreed to in writing, software distributed under the License
#  is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.

from typing import Tuple, Optional


class DnType:
    def __init__(
        self, token: int, class_: Tuple[str, ...], namespace: str = "", member: str = "", access: Optional[str] = None
    ):
        self.token: int = token
        self.access: Optional[str] = access
        self.namespace: str = namespace
        self.class_: Tuple[str, ...] = class_

        if member == ".ctor":
            member = "ctor"
        if member == ".cctor":
            member = "cctor"

        self.member: str = member

    def __hash__(self):
        return hash((self.token, self.access, self.namespace, self.class_, self.member))

    def __eq__(self, other):
        return (
            self.token == other.token
            and self.access == other.access