Coverage for src/castep_linter/fortran/identifier.py: 100%

1"""Fortran identifier Class Module"""

2 from castep_linter.fortran.fortran_node import FortranNode

3

4

5 class Identifier:

6 """Represents a type insensitive identifier in Fortran"""

7

8 def __init__(self, name: str):

9 self.lower_name = name.lower()

10

11 @classmethod

12 def from_node(cls, node: FortranNode) -> "Identifier":

13 """Create an identifier directly from a node"""

14 return Identifier(node.raw)

15

16 def __repr__(self):

17 return self.lower_name

18

19 def __hash__(self):

20 return hash(self.lower_name)

21

22 def __eq__(self, other):

23 if other is None:

24 return False

25 if isinstance(other, str):

26 return self.lower_name == other.lower()

27 if isinstance(other, Identifier):

28 return self.lower_name == other.lower_name.lower()

29 err = "Can only compare identifiers with other identifiers"

30 raise TypeError(err)