-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
115 lines (106 loc) · 5.68 KB
/
Copy pathmodels.py
File metadata and controls
115 lines (106 loc) · 5.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from typing import FrozenSet
from dataclasses import dataclass
@dataclass
class StyleError:
"""Represents a style violation."""
file_path: str
line_number: int
column: int
error_code: str
message: str
def __str__(self) -> str:
"""Converts the error dataclass to a string.
Returns:
str: the error as a str
"""
return f"{self.error_code} at {self.file_path}:{self.line_number}:{self.column} - {self.message}"
# Error codes following industry conventions (similar to flake8)
ERROR_CODES = {
'N801': 'class name should use PascalCase',
'N802': 'function name should use snake_case',
'N803': 'argument name should use snake_case',
'N804': 'variable name should use snake_case',
'N805': 'inappropriate use of name mangling',
'ANN001': 'missing type annotation for function argument',
'ANN002': 'missing return type annotation',
'D100': 'missing docstring in public module',
'D101': 'missing docstring in public class',
'D102': 'missing docstring in public method',
'D103': 'missing docstring in public function',
'D200': 'docstring should start with capital letter',
'D201': 'docstring should end with period',
'D300': 'missing Args section in docstring',
'D301': 'missing Returns section in docstring',
'D302': 'docstring Args section is malformed',
'D303': 'docstring Returns section is malformed',
'D304': 'argument not documented in docstring',
'D305': 'documented argument not found in function signature',
'D306': 'type mismatch between annotation and docstring',
'B006': 'mutable default argument',
# Import-related errors
'I100': 'imports not properly ordered (stdlib, third-party, local)',
'I101': 'unused import',
'I102': 'wildcard import should be avoided',
'I103': 'import should be absolute',
# Complexity errors
'C901': 'function is too complex, consider breaking into helper functions',
# Security errors
'S001': 'potential hardcoded password or secret',
'S002': 'potential SQL injection vulnerability',
'S003': 'potential shell injection vulnerability',
'S004': 'assert statement used in production code',
}
# Standard special methods and variables
SPECIAL_METHODS: FrozenSet[str] = frozenset([
'__init__', '__del__', '__repr__', '__str__', '__bytes__', '__format__',
'__lt__', '__le__', '__eq__', '__ne__', '__gt__', '__ge__', '__hash__',
'__bool__', '__call__', '__len__', '__getitem__', '__setitem__',
'__delitem__', '__iter__', '__next__', '__reversed__', '__contains__',
'__add__', '__sub__', '__mul__', '__matmul__', '__truediv__',
'__floordiv__', '__mod__', '__divmod__', '__pow__', '__lshift__',
'__rshift__', '__and__', '__xor__', '__or__', '__iadd__', '__isub__',
'__imul__', '__imatmul__', '__itruediv__', '__ifloordiv__', '__imod__',
'__ipow__', '__ilshift__', '__irshift__', '__iand__', '__ixor__',
'__ior__', '__neg__', '__pos__', '__abs__', '__invert__', '__complex__',
'__int__', '__float__', '__round__', '__index__', '__enter__',
'__exit__', '__await__', '__aiter__', '__anext__', '__aenter__',
'__aexit__', '__new__', '__post_init__', '__radd__', '__rsub__',
'__rmul__', '__rmatmul__', '__rtruediv__', '__rfloordiv__',
'__rmod__', '__rdivmod__', '__rpow__', '__rlshift__',
'__rrshift__', '__rand__', '__rxor__', '__ror__', '__copy__',
'__deepcopy__', '__getattr__', '__getattribute__', '__setattr__',
'__delattr__', '__dir__', '__get__', '__set__', '__delete__',
'__set_name__', '__slots__', '__weakref__', '__missing__',
'__length_hint__', '__class_getitem__', '__init_subclass__',
'__prepare__', '__instancecheck__', '__subclasscheck__',
'__reduce__', '__reduce_ex__', '__getnewargs__', '__getnewargs_ex__',
'__getstate__', '__setstate__', '__sizeof__', '__fspath__',
'__buffer__', '__release_buffer__', '__match_args__', '__ceil__',
'__floor__', '__trunc__', '__mro_entries__', '__orig_bases__',
'__parameters__', '__args__', '__origin__',
])
SPECIAL_VARIABLES: FrozenSet[str] = frozenset(['self', 'cls'])
PYTEST_METHODS: FrozenSet[str] = frozenset([
'setup_module', 'teardown_module', 'setup_class', 'teardown_class',
'setup_method', 'teardown_method', 'setup_function', 'teardown_function'
])
# Standard library modules (partial list - could be expanded)
STDLIB_MODULES: FrozenSet[str] = frozenset([
'os', 'sys', 'ast', 're', 'json', 'urllib', 'http', 'pathlib', 'datetime',
'collections', 'itertools', 'functools', 'operator', 'typing', 'dataclasses',
'argparse', 'logging', 'unittest', 'subprocess', 'threading', 'multiprocessing',
'sqlite3', 'csv', 'xml', 'email', 'hashlib', 'hmac', 'base64', 'pickle',
'tempfile', 'shutil', 'glob', 'fnmatch', 'linecache', 'textwrap', 'string',
'math', 'random', 'statistics', 'decimal', 'fractions', 'cmath', 'time',
'calendar', 'zoneinfo', 'locale', 'gettext', 'struct', 'codecs', 'unicodedata',
'io', 'gzip', 'bz2', 'lzma', 'zipfile', 'tarfile', 'configparser', 'netrc',
'xdrlib', 'plistlib', 'token', 'tokenize', 'keyword', 'pkgutil', 'modulefinder',
'runpy', 'importlib', 'parser', 'symbol', 'compiler', 'dis', 'pickletools',
'formatter', 'errno', 'ctypes', 'platform', 'curses', 'getpass', 'getopt',
'shlex', 'socketserver', 'wsgiref', 'webbrowser', 'cgi', 'cgitb', 'wsgiref',
'ftplib', 'poplib', 'imaplib', 'nntplib', 'smtplib', 'smtpd', 'telnetlib',
'uuid', 'socketserver', 'xmlrpc', 'ipaddress', 'mailcap', 'mailbox',
'mimetypes', 'uu', 'binascii', 'binhex', 'quopri', 'pty', 'fcntl', 'pipes',
'posixpath', 'ntpath', 'macpath', 'stat', 'statvfs', 'filecmp', 'tempfile',
'glob', 'fnmatch', 'linecache', 'shutil', 'macpath', 'dircache'
])