jw.util: Add @override
Add @override qualifiers to overridden methods. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
ae1445a08c
commit
e3c64f2efb
15 changed files with 42 additions and 8 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import argparse
|
||||
from typing import override
|
||||
|
||||
from collections import OrderedDict
|
||||
|
||||
|
|
@ -21,6 +22,7 @@ class ArgsContainer: # export
|
|||
raise Exception(f'No value for argument "{name}"')
|
||||
raise Exception(f'No argument "{name}" defined')
|
||||
|
||||
@override
|
||||
def __setattr__(self, name, value):
|
||||
if name not in self.__kwargs.keys():
|
||||
raise Exception(f'No argument "{name}" defined')
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import shlex
|
|||
import traceback
|
||||
|
||||
from collections import OrderedDict
|
||||
from typing import override
|
||||
|
||||
from .log import ERR, get_caller_pos, slog, slog_m
|
||||
|
||||
|
|
@ -88,12 +89,15 @@ class Options: # export
|
|||
return None
|
||||
return self.__dict[key]
|
||||
|
||||
@override
|
||||
def __str__(self):
|
||||
return ', '.join(str(p[0]) + ': ' + str(p[1]) for p in self.__data.pairs)
|
||||
|
||||
@override
|
||||
def __repr__(self):
|
||||
return self.__str__()
|
||||
|
||||
@override
|
||||
def __format__(self, fmt):
|
||||
return self.__str__()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import re
|
||||
from typing import override
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
|
@ -20,6 +21,7 @@ class Stack:
|
|||
def __init__(self, itemlist = []):
|
||||
self.items = itemlist
|
||||
|
||||
@override
|
||||
def __repr__(self):
|
||||
return str(self.items)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
from abc import abstractmethod
|
||||
from typing import override
|
||||
|
||||
from ..Process import Process as ProcessBase
|
||||
from .Signals import Signals
|
||||
|
|
@ -11,6 +12,7 @@ class Process(ProcessBase): # export
|
|||
super().__init__()
|
||||
self.aio = aio
|
||||
|
||||
@override
|
||||
@classmethod
|
||||
@abstractmethod
|
||||
def signals(cls):
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import asyncio
|
||||
import re
|
||||
from typing import override
|
||||
|
||||
from ..log import DEBUG, ERR, INFO, WARNING, slog
|
||||
|
||||
|
|
@ -14,6 +15,7 @@ class ShellCmd: # export
|
|||
self.name = name
|
||||
super().__init__()
|
||||
|
||||
@override
|
||||
def pipe_data_received(self, fd, data):
|
||||
stream = "stdout" if fd == 1 else ("stderr" if fd == 2 else str(fd))
|
||||
tag = stream + '@' + self.name
|
||||
|
|
@ -22,6 +24,7 @@ class ShellCmd: # export
|
|||
for line in data.split('\n'):
|
||||
slog(prio, "[%s] %s" % (tag, line.rstrip('\r\n')))
|
||||
|
||||
@override
|
||||
def process_exited(self):
|
||||
slog(DEBUG, "[%s] process exited" % (self.name))
|
||||
super().process_exited()
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
import asyncio
|
||||
|
||||
from typing import override
|
||||
|
||||
from ..Signals import Signals as SignalsBase
|
||||
|
||||
class Signals(SignalsBase):
|
||||
|
||||
# reimplemented from Signals
|
||||
@override
|
||||
@classmethod
|
||||
def _add_handler(cls, signal, handler):
|
||||
loop = asyncio.get_running_loop()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from __future__ import annotations
|
||||
from typing import Any, TYPE_CHECKING
|
||||
from typing import Any, TYPE_CHECKING, override
|
||||
|
||||
import abc
|
||||
|
||||
|
|
@ -24,12 +24,15 @@ class Queries(abc.ABC): # export
|
|||
|
||||
# -- implement API
|
||||
|
||||
@override
|
||||
def _run(self, session, *args, **kwargs) -> QueryResult:
|
||||
return self.__func(session, *args, **kwargs)
|
||||
|
||||
@override
|
||||
def _register(self):
|
||||
raise Exception('Can\'t call register on this object')
|
||||
|
||||
@override
|
||||
def _column_names(self) -> list[str]:
|
||||
return self.__query.column_names
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from __future__ import annotations
|
|||
|
||||
import abc
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Optional
|
||||
from typing import TYPE_CHECKING, Any, Optional, override
|
||||
|
||||
from ...log import ERR, throw
|
||||
|
||||
|
|
@ -27,9 +27,11 @@ class Column(abc.ABC): # export
|
|||
self.__foreign_keys_cached: bool = False
|
||||
self.__foreign_keys_by_table: Optional[dict[str, Any]] = None
|
||||
|
||||
@override
|
||||
def __repr__(self):
|
||||
return f'{self.__table.name}.{self.__name}: {self.__data_type}'
|
||||
|
||||
@override
|
||||
def __eq__(self, rhs) -> bool:
|
||||
if isinstance(rhs, Column):
|
||||
if self.__table != rhs.__table:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Optional, Any
|
||||
from typing import Optional, Any, override
|
||||
|
||||
class ColumnSet: # export
|
||||
|
||||
|
|
@ -26,12 +26,14 @@ class ColumnSet: # export
|
|||
def __iter__(self):
|
||||
yield from self.__columns
|
||||
|
||||
@override
|
||||
def __repr__(self):
|
||||
return '|'.join([col.name for col in self.__columns])
|
||||
|
||||
def __getitem__(self, index):
|
||||
return self.__columns[index]
|
||||
|
||||
@override
|
||||
def __eq__(self, rhs):
|
||||
if self.__table != rhs.__table:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Optional
|
||||
from typing import TYPE_CHECKING, Any, Optional, override
|
||||
|
||||
from ...log import WARNING, slog
|
||||
from .SingleForeignKey import SingleForeignKey
|
||||
|
|
@ -47,6 +47,7 @@ class CompositeForeignKey: # export
|
|||
def __iter__(self):
|
||||
yield from self.column_relations
|
||||
|
||||
@override
|
||||
def __repr__(self):
|
||||
ret = self.__table_rel_str()
|
||||
ret += ': ' + ', '.join(
|
||||
|
|
@ -57,6 +58,7 @@ class CompositeForeignKey: # export
|
|||
)
|
||||
return ret
|
||||
|
||||
@override
|
||||
def __eq__(self, rhs):
|
||||
if rhs.__child_col_set != self.__child_col_set:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from datetime import datetime
|
||||
from enum import Enum, auto
|
||||
from typing import Optional
|
||||
from typing import Optional, override
|
||||
|
||||
from ...log import ERR, throw
|
||||
|
||||
|
|
@ -50,12 +50,14 @@ class DataType: # export
|
|||
self.__id = type_id
|
||||
self.__size = size
|
||||
|
||||
@override
|
||||
def __repr__(self):
|
||||
ret = f'{self.__id.name}'
|
||||
if self.__size is not None:
|
||||
ret += f'({self.__size})'
|
||||
return ret
|
||||
|
||||
@override
|
||||
def __eq__(self, rhs):
|
||||
if self.__id != rhs.__id:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from __future__ import annotations
|
|||
|
||||
import abc
|
||||
|
||||
from typing import TYPE_CHECKING, Iterable, Optional
|
||||
from typing import TYPE_CHECKING, override, Iterable, Optional
|
||||
|
||||
from ...log import DEBUG, ERR, slog, throw
|
||||
|
||||
|
|
@ -61,6 +61,7 @@ class Schema(abc.ABC): # export
|
|||
def __iter__(self):
|
||||
yield from self.__tables.values()
|
||||
|
||||
@override
|
||||
def __repr__(self):
|
||||
return '|'.join([table.name for table in self.__tables.values()])
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, override
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .Column import Column
|
||||
|
|
@ -18,6 +18,7 @@ class SingleForeignKey:
|
|||
def __iter__(self):
|
||||
yield from self.__iterable
|
||||
|
||||
@override
|
||||
def __repr__(self):
|
||||
return (
|
||||
f'{self.__child_col.table.name}.{self.__child_col.name} -> '
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import abc
|
|||
import re
|
||||
|
||||
from collections import OrderedDict
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, override
|
||||
from urllib.parse import quote_plus
|
||||
|
||||
from ...log import ERR, WARNING, slog, throw
|
||||
|
|
@ -97,12 +97,14 @@ class Table(abc.ABC): # export
|
|||
def __iter__(self):
|
||||
yield from self.__columns.values()
|
||||
|
||||
@override
|
||||
def __repr__(self) -> str:
|
||||
return self.__name
|
||||
|
||||
def __getitem__(self, index):
|
||||
return self.__columns[index]
|
||||
|
||||
@override
|
||||
def __eq__(self, rhs) -> bool:
|
||||
if isinstance(rhs, Table):
|
||||
if self.__name != rhs.__name:
|
||||
|
|
@ -115,6 +117,7 @@ class Table(abc.ABC): # export
|
|||
throw(ERR, f'Tried to compare table {self} to type {type(rhs)}: {rhs}')
|
||||
return False # Unreachable but requested by mypy
|
||||
|
||||
@override
|
||||
def __hash__(self) -> int:
|
||||
return hash(self.name)
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ OTHER DEALINGS IN THE SOFTWARE.
|
|||
'''
|
||||
|
||||
import platform
|
||||
from typing import override
|
||||
|
||||
_python3 = int(platform.python_version_tuple()[0]) >= 3
|
||||
|
||||
|
|
@ -328,6 +329,7 @@ class multi_key_dict(object):
|
|||
else:
|
||||
return default
|
||||
|
||||
@override
|
||||
def __str__(self):
|
||||
items = []
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue