Skip to content

Commit

Permalink
Made abstract classes more formalised (cannot be instantiated without…
Browse files Browse the repository at this point in the history
… overriding abstract methods)
  • Loading branch information
titus-ong committed Aug 31, 2020
1 parent f0f4b5b commit 42d4028
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
7 changes: 5 additions & 2 deletions src/chordparser/music/hassymbol.py
Expand Up @@ -2,10 +2,13 @@


class HasSymbol:
"""Abstract class that contains a `Symbol`."""

_symbol: Symbol # To be defined in concrete class

@property
def symbol(self):
# To be implemented in concrete class
raise NotImplementedError
return self._symbol

def raise_by(self, steps=1):
"""Raise the pitch by changing only its `Symbol`.
Expand Down
17 changes: 10 additions & 7 deletions src/chordparser/music/notationparser.py
@@ -1,9 +1,16 @@
from abc import ABCMeta, abstractmethod
import re


class NotationParserTemplate:
class NotationParserTemplate(metaclass=ABCMeta):
"""Abstract class for parsing notation."""

_pattern: str # To be defined in concrete class

@property
def pattern(self):
return self._pattern

def parse_notation(self, notation):
regex = self._to_regex_object(notation)
if self._invalid_notation(regex):
Expand All @@ -22,13 +29,9 @@ def _to_regex_object(self, notation):
def _invalid_notation(self, regex):
return not regex

@abstractmethod
def _split_into_groups(self, regex):
# To be implemented in concrete class
raise NotImplementedError

@property
def pattern(self):
return self._pattern
pass

def get_num_groups(self):
regex = re.compile(self._pattern)
Expand Down
4 changes: 0 additions & 4 deletions src/chordparser/music/note.py
Expand Up @@ -74,10 +74,6 @@ def _set(self, notation):
def letter(self):
return self._letter

@property
def symbol(self):
return self._symbol

def as_steps(self):
"""Return the number of steps of the `Note` above C.
Expand Down
4 changes: 0 additions & 4 deletions src/chordparser/music/scaledegree.py
Expand Up @@ -59,10 +59,6 @@ def _set(self, degree, symbol):
def degree(self):
return self._degree

@property
def symbol(self):
return self._symbol

@classmethod
def from_components(cls, degree, symbol=""):
"""Create a `ScaleDegree` from its degree and symbol components.
Expand Down

0 comments on commit 42d4028

Please sign in to comment.