Passed
Push — main ( f8eb74...8d48ee )
by Ray
01:13
created

menderbot.antlr_generated.PythonParserBase   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 61.76 %

Importance

Changes 0
Metric Value
eloc 25
dl 21
loc 34
rs 10
c 0
b 0
f 0
wmc 6

How to fix   Duplicated Code   

Duplicated Code

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