flake8-digit-separator 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- flake8_digit_separator-0.1.0/LICENSE +21 -0
- flake8_digit_separator-0.1.0/PKG-INFO +75 -0
- flake8_digit_separator-0.1.0/README.md +56 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/__init__.py +0 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/__version__.py +45 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/checker.py +74 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/classifiers/__init__.py +0 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/classifiers/base.py +72 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/classifiers/classifier_binary.py +41 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/classifiers/classifier_complex.py +40 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/classifiers/classifier_float.py +41 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/classifiers/classifier_hex.py +41 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/classifiers/classifier_int.py +37 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/classifiers/classifier_octal.py +41 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/classifiers/classifier_scientific.py +40 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/classifiers/registry.py +56 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/classifiers/types.py +3 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/error.py +16 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/fds_numbers/__init__.py +0 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/fds_numbers/base.py +39 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/fds_numbers/enums.py +30 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/fds_numbers/fds_numbers.py +72 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/fds_numbers/types.py +16 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/rules/__init__.py +0 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/rules/base.py +42 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/rules/rules.py +31 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/types.py +3 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/validators/__init__.py +0 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/validators/base.py +100 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/validators/registry.py +59 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/validators/types.py +11 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/validators/validator_binary.py +48 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/validators/validator_float.py +57 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/validators/validator_hex.py +52 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/validators/validator_int.py +57 -0
- flake8_digit_separator-0.1.0/flake8_digit_separator/validators/validator_octal.py +57 -0
- flake8_digit_separator-0.1.0/pyproject.toml +55 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Timur Valiev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: flake8-digit-separator
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Correct placement of separators
|
|
5
|
+
License: MIT
|
|
6
|
+
Keywords: flake8,linter,PEP515,separator,code-style,python-linter,linting,code-standards,code-quality,flake8-plugin,flake8-formatter,code-checker,numbers,digits,FDS
|
|
7
|
+
Author: Timur Valiev
|
|
8
|
+
Author-email: cptchunk@yandex.ru
|
|
9
|
+
Requires-Python: >=3.10,<4.0
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Requires-Dist: flake8 (>=7.1,<8.0)
|
|
17
|
+
Project-URL: Homepage, https://github.com/imtoopunkforyou/flake8-digit-separator
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# flake8-digit-separator
|
|
21
|
+
[](https://github.com/pytest-dev/pytest-cov)
|
|
22
|
+
[](https://github.com/imtoopunkforyou/flake8-digit-separator/actions/workflows/tests.yaml)
|
|
23
|
+
[](https://pypi.org/project/flake8-digit-separator)
|
|
24
|
+
[](https://pypi.org/project/flake8-digit-separator)
|
|
25
|
+
[](https://pypi.org/project/flake8-digit-separator)
|
|
26
|
+
[](https://github.com/wemake-services/wemake-python-styleguide)
|
|
27
|
+
[](https://github.com/imtoopunkforyou/flake8-digit-separator/blob/main/LICENSE)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
<p align="center">
|
|
31
|
+
<a href="https://pypi.org/project/flake8-digit-separator">
|
|
32
|
+
<img src="https://raw.githubusercontent.com/imtoopunkforyou/flake8-digit-separator/main/.github/badge/logo.png"
|
|
33
|
+
alt="FDS logo">
|
|
34
|
+
</a>
|
|
35
|
+
</p>
|
|
36
|
+
|
|
37
|
+
A set of [rules](https://github.com/imtoopunkforyou/flake8-digit-separator?tab=readme-ov-file#rules) on top of the capabilities provided by [PEP515](https://peps.python.org/pep-0515/).
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
correct_int = 10_000
|
|
41
|
+
correct_float = 10_000.1_234
|
|
42
|
+
correct_binary = 0b_1101_1001
|
|
43
|
+
correct_octal = 0o_134_155
|
|
44
|
+
correct_hex = 0x_CAFE_F00D
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
```bash
|
|
49
|
+
pip install flake8-digit-separator
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Dependencies
|
|
53
|
+
- `python (>=3.10, <4.0)`
|
|
54
|
+
- `flake8 (>=7.1, <8.0)`
|
|
55
|
+
|
|
56
|
+
## Usage
|
|
57
|
+
```bash
|
|
58
|
+
flake8 . --select FDS
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Rules
|
|
62
|
+
[PEP515](https://peps.python.org/pep-0515/) allows separators, but does not impose any restrictions on their position in a number (except that a number should not start/end with a separator and there should not be two separators in a row). To introduce more rigor and beauty into the code, we have written a few simple rules that we suggest following.
|
|
63
|
+
|
|
64
|
+
| Rule | Number | Description | Correct | Wrong |
|
|
65
|
+
|--------|---------|------------------------------------------|---------------|-------------|
|
|
66
|
+
| FDS100 | integer | Group by 3s from right | 10_000 | 10_0 |
|
|
67
|
+
| FDS200 | float | Group by 3s from right | 10_000.1_234 | 1_0_0.123_4 |
|
|
68
|
+
| FDS300 | binary | Group by 4s from right after prefix `0b` | 0b_1101_1001 | 0b110_11 |
|
|
69
|
+
| FDS400 | octal | Group by 3s from right after prefix `0o` | 0o_12_134_155 | 0o1_23_45 |
|
|
70
|
+
| FDS500 | hex | Group by 4s from right after prefix `0x` | 0x_CAFE_F00D | 0xCAFEF0_0D |
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
[FDS](https://github.com/imtoopunkforyou/flake8-digit-separator) is released under the MIT License. See the bundled [LICENSE](https://github.com/imtoopunkforyou/flake8-digit-separator/blob/main/LICENSE) file for details.
|
|
74
|
+
|
|
75
|
+
The logo was created using [Font Meme](https://fontmeme.com/graffiti-creator/).
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# flake8-digit-separator
|
|
2
|
+
[](https://github.com/pytest-dev/pytest-cov)
|
|
3
|
+
[](https://github.com/imtoopunkforyou/flake8-digit-separator/actions/workflows/tests.yaml)
|
|
4
|
+
[](https://pypi.org/project/flake8-digit-separator)
|
|
5
|
+
[](https://pypi.org/project/flake8-digit-separator)
|
|
6
|
+
[](https://pypi.org/project/flake8-digit-separator)
|
|
7
|
+
[](https://github.com/wemake-services/wemake-python-styleguide)
|
|
8
|
+
[](https://github.com/imtoopunkforyou/flake8-digit-separator/blob/main/LICENSE)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://pypi.org/project/flake8-digit-separator">
|
|
13
|
+
<img src="https://raw.githubusercontent.com/imtoopunkforyou/flake8-digit-separator/main/.github/badge/logo.png"
|
|
14
|
+
alt="FDS logo">
|
|
15
|
+
</a>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
A set of [rules](https://github.com/imtoopunkforyou/flake8-digit-separator?tab=readme-ov-file#rules) on top of the capabilities provided by [PEP515](https://peps.python.org/pep-0515/).
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
correct_int = 10_000
|
|
22
|
+
correct_float = 10_000.1_234
|
|
23
|
+
correct_binary = 0b_1101_1001
|
|
24
|
+
correct_octal = 0o_134_155
|
|
25
|
+
correct_hex = 0x_CAFE_F00D
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
```bash
|
|
30
|
+
pip install flake8-digit-separator
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Dependencies
|
|
34
|
+
- `python (>=3.10, <4.0)`
|
|
35
|
+
- `flake8 (>=7.1, <8.0)`
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
```bash
|
|
39
|
+
flake8 . --select FDS
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Rules
|
|
43
|
+
[PEP515](https://peps.python.org/pep-0515/) allows separators, but does not impose any restrictions on their position in a number (except that a number should not start/end with a separator and there should not be two separators in a row). To introduce more rigor and beauty into the code, we have written a few simple rules that we suggest following.
|
|
44
|
+
|
|
45
|
+
| Rule | Number | Description | Correct | Wrong |
|
|
46
|
+
|--------|---------|------------------------------------------|---------------|-------------|
|
|
47
|
+
| FDS100 | integer | Group by 3s from right | 10_000 | 10_0 |
|
|
48
|
+
| FDS200 | float | Group by 3s from right | 10_000.1_234 | 1_0_0.123_4 |
|
|
49
|
+
| FDS300 | binary | Group by 4s from right after prefix `0b` | 0b_1101_1001 | 0b110_11 |
|
|
50
|
+
| FDS400 | octal | Group by 3s from right after prefix `0o` | 0o_12_134_155 | 0o1_23_45 |
|
|
51
|
+
| FDS500 | hex | Group by 4s from right after prefix `0x` | 0x_CAFE_F00D | 0xCAFEF0_0D |
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
[FDS](https://github.com/imtoopunkforyou/flake8-digit-separator) is released under the MIT License. See the bundled [LICENSE](https://github.com/imtoopunkforyou/flake8-digit-separator/blob/main/LICENSE) file for details.
|
|
55
|
+
|
|
56
|
+
The logo was created using [Font Meme](https://fontmeme.com/graffiti-creator/).
|
|
File without changes
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# ___ ___ ___
|
|
2
|
+
# /\ \ /\ \ /\ \
|
|
3
|
+
# /::\ \ /::\ \ /::\ \
|
|
4
|
+
# /:/\:\ \ /:/\:\ \ /:/\ \ \
|
|
5
|
+
# /::\~\:\ \ /:/ \:\__\ _\:\~\ \ \
|
|
6
|
+
# /:/\:\ \:\__\ /:/__/ \:|__| /\ \:\ \ \__\
|
|
7
|
+
# \/__\:\ \/__/ \:\ \ /:/ / \:\ \:\ \/__/
|
|
8
|
+
# \:\__\ \:\ /:/ / \:\ \:\__\
|
|
9
|
+
# \/__/ \:\/:/ / \:\/:/ /
|
|
10
|
+
# \::/__/ \::/ /
|
|
11
|
+
# ~~ \/__/
|
|
12
|
+
|
|
13
|
+
from importlib.metadata import PackageMetadata, metadata
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from typing import Final
|
|
16
|
+
|
|
17
|
+
pkg_data: PackageMetadata = metadata(str(Path(__file__).parent.name))
|
|
18
|
+
|
|
19
|
+
NAME: Final[str] = pkg_data['Name']
|
|
20
|
+
"""Package name."""
|
|
21
|
+
|
|
22
|
+
VERSION: Final[str] = pkg_data['Version']
|
|
23
|
+
"""Package version."""
|
|
24
|
+
|
|
25
|
+
AUTHOR: Final[str] = pkg_data['Author']
|
|
26
|
+
"""Package author."""
|
|
27
|
+
|
|
28
|
+
AUTHOR_EMAIL: Final[str] = pkg_data['Author-email']
|
|
29
|
+
"""Package author e-mail."""
|
|
30
|
+
|
|
31
|
+
LICENSE: Final[str] = pkg_data['License']
|
|
32
|
+
"""Package license."""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def get_package_information() -> dict[str, str]:
|
|
36
|
+
"""Short info about package."""
|
|
37
|
+
pkg_info = {
|
|
38
|
+
'name': NAME,
|
|
39
|
+
'version': VERSION,
|
|
40
|
+
'author': AUTHOR,
|
|
41
|
+
'author_email': AUTHOR_EMAIL,
|
|
42
|
+
'license': LICENSE,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return pkg_info
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import ast
|
|
2
|
+
import tokenize
|
|
3
|
+
from typing import Iterator, TypeVar
|
|
4
|
+
|
|
5
|
+
from flake8_digit_separator import __version__ as version
|
|
6
|
+
from flake8_digit_separator.classifiers.registry import ClassifierRegistry
|
|
7
|
+
from flake8_digit_separator.error import Error
|
|
8
|
+
from flake8_digit_separator.fds_numbers.types import FDSNumbersAlias
|
|
9
|
+
from flake8_digit_separator.types import ErrorMessage
|
|
10
|
+
from flake8_digit_separator.validators.registry import ValidatorRegistry
|
|
11
|
+
|
|
12
|
+
SelfChecker = TypeVar('SelfChecker', bound='Checker')
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Checker:
|
|
16
|
+
name = version.NAME
|
|
17
|
+
version = version.VERSION
|
|
18
|
+
|
|
19
|
+
def __init__(
|
|
20
|
+
self: SelfChecker,
|
|
21
|
+
tree: ast.AST,
|
|
22
|
+
file_tokens: list[tokenize.TokenInfo],
|
|
23
|
+
) -> None:
|
|
24
|
+
self.file_tokens = file_tokens
|
|
25
|
+
|
|
26
|
+
def run(self: SelfChecker) -> Iterator[ErrorMessage]:
|
|
27
|
+
"""
|
|
28
|
+
Entry point and start of validation.
|
|
29
|
+
|
|
30
|
+
1. Check that the token is a number.
|
|
31
|
+
2. Classify the token.
|
|
32
|
+
3. Validate the token.
|
|
33
|
+
4. Display an error.
|
|
34
|
+
|
|
35
|
+
:yield: FDS rule that was broken.
|
|
36
|
+
:rtype: Iterator[ErrorMessage]
|
|
37
|
+
"""
|
|
38
|
+
for token in self.file_tokens:
|
|
39
|
+
if token.type == tokenize.NUMBER:
|
|
40
|
+
error = self._process_number_token(token)
|
|
41
|
+
if error:
|
|
42
|
+
yield error.as_tuple()
|
|
43
|
+
|
|
44
|
+
def _process_number_token(
|
|
45
|
+
self: SelfChecker,
|
|
46
|
+
token: tokenize.TokenInfo,
|
|
47
|
+
) -> Error | None:
|
|
48
|
+
number = self._classify(token)
|
|
49
|
+
|
|
50
|
+
if number:
|
|
51
|
+
if not number.is_supported:
|
|
52
|
+
return None
|
|
53
|
+
|
|
54
|
+
validator = ValidatorRegistry.get_validator(number)
|
|
55
|
+
if validator.validate():
|
|
56
|
+
return None
|
|
57
|
+
|
|
58
|
+
return Error(
|
|
59
|
+
line=token.start[0],
|
|
60
|
+
column=token.start[1],
|
|
61
|
+
message=validator.error_message,
|
|
62
|
+
object_type=type(self),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
return None
|
|
66
|
+
|
|
67
|
+
def _classify(self: SelfChecker, token: tokenize.TokenInfo) -> FDSNumbersAlias | None:
|
|
68
|
+
classifiers = ClassifierRegistry.get_ordered_classifiers()
|
|
69
|
+
for classifier in classifiers:
|
|
70
|
+
number = classifier(token.string).classify()
|
|
71
|
+
if number:
|
|
72
|
+
break
|
|
73
|
+
|
|
74
|
+
return number if number else None
|
|
File without changes
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from typing import TypeAlias, TypeVar
|
|
3
|
+
|
|
4
|
+
from flake8_digit_separator.classifiers.types import TokenLikeStr
|
|
5
|
+
from flake8_digit_separator.fds_numbers.fds_numbers import (
|
|
6
|
+
BinaryNumber,
|
|
7
|
+
ComplexNumber,
|
|
8
|
+
FloatNumber,
|
|
9
|
+
HexNumber,
|
|
10
|
+
IntNumber,
|
|
11
|
+
OctalNumber,
|
|
12
|
+
ScientificNumber,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
SelfClassifier = TypeVar('SelfClassifier', bound='Classifier')
|
|
16
|
+
SelfBaseClassifier = TypeVar('SelfBaseClassifier', bound='BaseClassifier')
|
|
17
|
+
|
|
18
|
+
LowerTokenLikeStr: TypeAlias = str
|
|
19
|
+
FDSNumbersWithPrefixAlias: TypeAlias = OctalNumber | HexNumber | BinaryNumber
|
|
20
|
+
FDSNumbersUnsupportedAlias: TypeAlias = ScientificNumber | ComplexNumber
|
|
21
|
+
FDSNumbersAlias: TypeAlias = IntNumber | FloatNumber | FDSNumbersUnsupportedAlias | FDSNumbersWithPrefixAlias
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class Classifier(ABC):
|
|
25
|
+
"""Abstract classifier class."""
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
@abstractmethod
|
|
29
|
+
def token(self: SelfClassifier) -> TokenLikeStr:
|
|
30
|
+
"""
|
|
31
|
+
Token string from `tokenize.TokenInfo` object.
|
|
32
|
+
|
|
33
|
+
:return: Token like string.
|
|
34
|
+
:rtype: TokenLikeStr
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
@abstractmethod
|
|
39
|
+
def token_lower(self: SelfClassifier) -> LowerTokenLikeStr:
|
|
40
|
+
"""
|
|
41
|
+
Token string from `tokenize.TokenInfo` object in lower case.
|
|
42
|
+
|
|
43
|
+
:return: Token like string in lower case.
|
|
44
|
+
:rtype: LowerTokenLikeStr
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
@abstractmethod
|
|
48
|
+
def classify(self: SelfClassifier) -> FDSNumbersAlias | None:
|
|
49
|
+
"""
|
|
50
|
+
Determines what specific number the token refers to.
|
|
51
|
+
|
|
52
|
+
:return: Object of a specific number.
|
|
53
|
+
:rtype: FDSNumbersAlias | None
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class BaseClassifier(Classifier):
|
|
58
|
+
"""
|
|
59
|
+
Base classifier class.
|
|
60
|
+
|
|
61
|
+
Specific classifiers should be inherited from this class.
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def token_lower(self: SelfBaseClassifier) -> LowerTokenLikeStr:
|
|
66
|
+
"""
|
|
67
|
+
Token string from `tokenize.TokenInfo` object in lower case.
|
|
68
|
+
|
|
69
|
+
:return: Token like string in lower case.
|
|
70
|
+
:rtype: LowerTokenLikeStr
|
|
71
|
+
"""
|
|
72
|
+
return self.token.lower()
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from typing import TypeVar, final
|
|
2
|
+
|
|
3
|
+
from flake8_digit_separator.classifiers.base import BaseClassifier
|
|
4
|
+
from flake8_digit_separator.classifiers.types import TokenLikeStr
|
|
5
|
+
from flake8_digit_separator.fds_numbers.enums import NumberPrefix
|
|
6
|
+
from flake8_digit_separator.fds_numbers.fds_numbers import BinaryNumber
|
|
7
|
+
|
|
8
|
+
SelfBinaryClassifier = TypeVar('SelfBinaryClassifier', bound='BinaryClassifier')
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@final
|
|
12
|
+
class BinaryClassifier(BaseClassifier):
|
|
13
|
+
"""Classifier for binary numbers."""
|
|
14
|
+
|
|
15
|
+
def __init__(
|
|
16
|
+
self: SelfBinaryClassifier,
|
|
17
|
+
token: TokenLikeStr,
|
|
18
|
+
) -> None:
|
|
19
|
+
self._token = token
|
|
20
|
+
|
|
21
|
+
def classify(self: SelfBinaryClassifier) -> BinaryNumber | None:
|
|
22
|
+
"""
|
|
23
|
+
Returns a binary number if it matches.
|
|
24
|
+
|
|
25
|
+
:return: Binary number
|
|
26
|
+
:rtype: BinaryNumber | None
|
|
27
|
+
"""
|
|
28
|
+
if self.token_lower.startswith(NumberPrefix.BINARY.get_value_without_separator()):
|
|
29
|
+
return BinaryNumber(self.token_lower)
|
|
30
|
+
|
|
31
|
+
return None
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def token(self: SelfBinaryClassifier) -> TokenLikeStr:
|
|
35
|
+
"""
|
|
36
|
+
Token string from `tokenize.TokenInfo` object.
|
|
37
|
+
|
|
38
|
+
:return: Token like string.
|
|
39
|
+
:rtype: TokenLikeStr
|
|
40
|
+
"""
|
|
41
|
+
return self._token
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from typing import TypeVar, final
|
|
2
|
+
|
|
3
|
+
from flake8_digit_separator.classifiers.base import BaseClassifier
|
|
4
|
+
from flake8_digit_separator.classifiers.types import TokenLikeStr
|
|
5
|
+
from flake8_digit_separator.fds_numbers.fds_numbers import ComplexNumber
|
|
6
|
+
|
|
7
|
+
SelfComplexClassifier = TypeVar('SelfComplexClassifier', bound='ComplexClassifier')
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@final
|
|
11
|
+
class ComplexClassifier(BaseClassifier):
|
|
12
|
+
"""Classifier for complex numbers."""
|
|
13
|
+
|
|
14
|
+
def __init__(
|
|
15
|
+
self: SelfComplexClassifier,
|
|
16
|
+
token: TokenLikeStr,
|
|
17
|
+
) -> None:
|
|
18
|
+
self._token = token
|
|
19
|
+
|
|
20
|
+
def classify(self: SelfComplexClassifier) -> ComplexNumber | None:
|
|
21
|
+
"""
|
|
22
|
+
Returns a complex number if it matches.
|
|
23
|
+
|
|
24
|
+
:return: Complex number
|
|
25
|
+
:rtype: ComplexNumber | None
|
|
26
|
+
"""
|
|
27
|
+
if 'j' in self.token_lower:
|
|
28
|
+
return ComplexNumber(self.token_lower)
|
|
29
|
+
|
|
30
|
+
return None
|
|
31
|
+
|
|
32
|
+
@property
|
|
33
|
+
def token(self: SelfComplexClassifier) -> TokenLikeStr:
|
|
34
|
+
"""
|
|
35
|
+
Token string from `tokenize.TokenInfo` object.
|
|
36
|
+
|
|
37
|
+
:return: Token like string.
|
|
38
|
+
:rtype: TokenLikeStr
|
|
39
|
+
"""
|
|
40
|
+
return self._token
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from typing import TypeVar, final
|
|
2
|
+
|
|
3
|
+
from flake8_digit_separator.classifiers.base import BaseClassifier
|
|
4
|
+
from flake8_digit_separator.classifiers.types import TokenLikeStr
|
|
5
|
+
from flake8_digit_separator.fds_numbers.enums import NumberDelimiter
|
|
6
|
+
from flake8_digit_separator.fds_numbers.fds_numbers import FloatNumber
|
|
7
|
+
|
|
8
|
+
SelfFloatClassifier = TypeVar('SelfFloatClassifier', bound='FloatClassifier')
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@final
|
|
12
|
+
class FloatClassifier(BaseClassifier):
|
|
13
|
+
"""Classifier for float numbers."""
|
|
14
|
+
|
|
15
|
+
def __init__(
|
|
16
|
+
self: SelfFloatClassifier,
|
|
17
|
+
token: TokenLikeStr,
|
|
18
|
+
) -> None:
|
|
19
|
+
self._token = token
|
|
20
|
+
|
|
21
|
+
def classify(self: SelfFloatClassifier) -> FloatNumber | None:
|
|
22
|
+
"""
|
|
23
|
+
Returns a float number if it matches.
|
|
24
|
+
|
|
25
|
+
:return: Float number
|
|
26
|
+
:rtype: FloatNumber | None
|
|
27
|
+
"""
|
|
28
|
+
if NumberDelimiter.FLOAT.value in self.token:
|
|
29
|
+
return FloatNumber(self.token)
|
|
30
|
+
|
|
31
|
+
return None
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def token(self: SelfFloatClassifier) -> TokenLikeStr:
|
|
35
|
+
"""
|
|
36
|
+
Token string from `tokenize.TokenInfo` object.
|
|
37
|
+
|
|
38
|
+
:return: Token like string.
|
|
39
|
+
:rtype: TokenLikeStr
|
|
40
|
+
"""
|
|
41
|
+
return self._token
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from typing import TypeVar, final
|
|
2
|
+
|
|
3
|
+
from flake8_digit_separator.classifiers.base import BaseClassifier
|
|
4
|
+
from flake8_digit_separator.classifiers.types import TokenLikeStr
|
|
5
|
+
from flake8_digit_separator.fds_numbers.enums import NumberPrefix
|
|
6
|
+
from flake8_digit_separator.fds_numbers.fds_numbers import HexNumber
|
|
7
|
+
|
|
8
|
+
SelfHexClassifier = TypeVar('SelfHexClassifier', bound='HexClassifier')
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@final
|
|
12
|
+
class HexClassifier(BaseClassifier):
|
|
13
|
+
"""Classifier for hex numbers."""
|
|
14
|
+
|
|
15
|
+
def __init__(
|
|
16
|
+
self: SelfHexClassifier,
|
|
17
|
+
token: TokenLikeStr,
|
|
18
|
+
) -> None:
|
|
19
|
+
self._token = token
|
|
20
|
+
|
|
21
|
+
def classify(self: SelfHexClassifier) -> HexNumber | None:
|
|
22
|
+
"""
|
|
23
|
+
Returns a hex number if it matches.
|
|
24
|
+
|
|
25
|
+
:return: Hex number
|
|
26
|
+
:rtype: HexNumber | None
|
|
27
|
+
"""
|
|
28
|
+
if self.token_lower.startswith(NumberPrefix.HEX.get_value_without_separator()):
|
|
29
|
+
return HexNumber(self.token_lower)
|
|
30
|
+
|
|
31
|
+
return None
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def token(self: SelfHexClassifier) -> TokenLikeStr:
|
|
35
|
+
"""
|
|
36
|
+
Token string from `tokenize.TokenInfo` object.
|
|
37
|
+
|
|
38
|
+
:return: Token like string.
|
|
39
|
+
:rtype: TokenLikeStr
|
|
40
|
+
"""
|
|
41
|
+
return self._token
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from typing import TypeVar, final
|
|
2
|
+
|
|
3
|
+
from flake8_digit_separator.classifiers.base import BaseClassifier
|
|
4
|
+
from flake8_digit_separator.classifiers.types import TokenLikeStr
|
|
5
|
+
from flake8_digit_separator.fds_numbers.fds_numbers import IntNumber
|
|
6
|
+
|
|
7
|
+
SelfIntClassifier = TypeVar('SelfIntClassifier', bound='IntClassifier')
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@final
|
|
11
|
+
class IntClassifier(BaseClassifier):
|
|
12
|
+
"""Classifier for int numbers."""
|
|
13
|
+
|
|
14
|
+
def __init__(
|
|
15
|
+
self: SelfIntClassifier,
|
|
16
|
+
token: TokenLikeStr,
|
|
17
|
+
) -> None:
|
|
18
|
+
self._token = token
|
|
19
|
+
|
|
20
|
+
def classify(self: SelfIntClassifier) -> IntNumber:
|
|
21
|
+
"""
|
|
22
|
+
Returns a int number if it matches.
|
|
23
|
+
|
|
24
|
+
:return: Int number
|
|
25
|
+
:rtype: IntNumber
|
|
26
|
+
"""
|
|
27
|
+
return IntNumber(self.token)
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
def token(self: SelfIntClassifier) -> TokenLikeStr:
|
|
31
|
+
"""
|
|
32
|
+
Token string from `tokenize.TokenInfo` object.
|
|
33
|
+
|
|
34
|
+
:return: Token like string.
|
|
35
|
+
:rtype: TokenLikeStr
|
|
36
|
+
"""
|
|
37
|
+
return self._token
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from typing import TypeVar, final
|
|
2
|
+
|
|
3
|
+
from flake8_digit_separator.classifiers.base import BaseClassifier
|
|
4
|
+
from flake8_digit_separator.classifiers.types import TokenLikeStr
|
|
5
|
+
from flake8_digit_separator.fds_numbers.enums import NumberPrefix
|
|
6
|
+
from flake8_digit_separator.fds_numbers.fds_numbers import OctalNumber
|
|
7
|
+
|
|
8
|
+
SelfOctalClassifier = TypeVar('SelfOctalClassifier', bound='OctalClassifier')
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@final
|
|
12
|
+
class OctalClassifier(BaseClassifier):
|
|
13
|
+
"""Classifier for octal numbers."""
|
|
14
|
+
|
|
15
|
+
def __init__(
|
|
16
|
+
self: SelfOctalClassifier,
|
|
17
|
+
token: TokenLikeStr,
|
|
18
|
+
) -> None:
|
|
19
|
+
self._token = token
|
|
20
|
+
|
|
21
|
+
def classify(self: SelfOctalClassifier) -> OctalNumber | None:
|
|
22
|
+
"""
|
|
23
|
+
Returns a octal number if it matches.
|
|
24
|
+
|
|
25
|
+
:return: Octal number
|
|
26
|
+
:rtype: OctalNumber | None
|
|
27
|
+
"""
|
|
28
|
+
if self.token_lower.startswith(NumberPrefix.OCTAL.get_value_without_separator()):
|
|
29
|
+
return OctalNumber(self.token_lower)
|
|
30
|
+
|
|
31
|
+
return None
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def token(self: SelfOctalClassifier) -> TokenLikeStr:
|
|
35
|
+
"""
|
|
36
|
+
Token string from `tokenize.TokenInfo` object.
|
|
37
|
+
|
|
38
|
+
:return: Token like string.
|
|
39
|
+
:rtype: TokenLikeStr
|
|
40
|
+
"""
|
|
41
|
+
return self._token
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from typing import TypeVar, final
|
|
2
|
+
|
|
3
|
+
from flake8_digit_separator.classifiers.base import BaseClassifier
|
|
4
|
+
from flake8_digit_separator.classifiers.types import TokenLikeStr
|
|
5
|
+
from flake8_digit_separator.fds_numbers.fds_numbers import ScientificNumber
|
|
6
|
+
|
|
7
|
+
SelfScientifiClassifier = TypeVar('SelfScientifiClassifier', bound='ScientifiClassifier')
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@final
|
|
11
|
+
class ScientifiClassifier(BaseClassifier):
|
|
12
|
+
"""Classifier for scientific numbers."""
|
|
13
|
+
|
|
14
|
+
def __init__(
|
|
15
|
+
self: SelfScientifiClassifier,
|
|
16
|
+
token: TokenLikeStr,
|
|
17
|
+
) -> None:
|
|
18
|
+
self._token = token
|
|
19
|
+
|
|
20
|
+
def classify(self: SelfScientifiClassifier) -> ScientificNumber | None:
|
|
21
|
+
"""
|
|
22
|
+
Returns a scientific number if it matches.
|
|
23
|
+
|
|
24
|
+
:return: Scientific number
|
|
25
|
+
:rtype: ScientificNumber | None
|
|
26
|
+
"""
|
|
27
|
+
if 'e' in self.token_lower:
|
|
28
|
+
return ScientificNumber(self.token_lower)
|
|
29
|
+
|
|
30
|
+
return None
|
|
31
|
+
|
|
32
|
+
@property
|
|
33
|
+
def token(self: SelfScientifiClassifier) -> TokenLikeStr:
|
|
34
|
+
"""
|
|
35
|
+
Token string from `tokenize.TokenInfo` object.
|
|
36
|
+
|
|
37
|
+
:return: Token like string.
|
|
38
|
+
:rtype: TokenLikeStr
|
|
39
|
+
"""
|
|
40
|
+
return self._token
|