| Total Complexity | 6 |
| Total Lines | 34 |
| Duplicated Lines | 61.76 % |
| Changes | 0 | ||
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | import sys |
||
| 2 | from enum import Enum |
||
| 3 | from typing import TextIO |
||
| 4 | |||
| 5 | from antlr4 import Parser, TokenStream |
||
| 6 | |||
| 7 | |||
| 8 | class PythonVersion(Enum): |
||
| 9 | Autodetect = 0 |
||
| 10 | Python2 = 2 |
||
| 11 | Python3 = 3 |
||
| 12 | |||
| 13 | class PythonParserBase(Parser): |
||
| 14 | def __init__(self, input_stream: TokenStream, output: TextIO = sys.stdout): |
||
| 15 | super().__init__(input_stream, output) |
||
| 16 | self.__version = PythonVersion.Autodetect |
||
| 17 | |||
| 18 | @property |
||
| 19 | def version(self) -> PythonVersion: |
||
| 20 | return self.__version |
||
| 21 | |||
| 22 | @version.setter |
||
| 23 | def version(self, version): |
||
| 24 | if isinstance(version, PythonVersion): |
||
| 25 | self.__version = version |
||
| 26 | else: |
||
| 27 | self.__version = PythonVersion(version) |
||
| 28 | |||
| 29 | def CheckVersion(self, version: int) -> bool: |
||
| 30 | return self.__version == PythonVersion.Autodetect or version == self.__version.value |
||
| 31 | |||
| 32 | def SetVersion(self, required_version: int) -> None: |
||
| 33 | self.__version = PythonVersion(required_version) |
||
| 34 |