Fix functions definition with stricter positional or keyword restrictions

This commit is contained in:
Gregoo 2025-01-22 16:36:35 +01:00
parent 0e977fd01d
commit c977217f48
21 changed files with 48 additions and 24 deletions

View File

@ -16,6 +16,7 @@ class BrickConfiguration(object):
def __init__(
self,
/,
*,
n: str,
e: str | None = None,
d: Any = None,

View File

@ -71,7 +71,7 @@ class BrickInstructions(object):
)
# Compute the path of an instruction file
def path(self, /, filename=None) -> str:
def path(self, /, *, filename=None) -> str:
if filename is None:
filename = self.filename
@ -99,7 +99,7 @@ class BrickInstructions(object):
# Upload a new instructions file
def upload(self, file: FileStorage, /) -> None:
target = self.path(secure_filename(self.filename))
target = self.path(filename=secure_filename(self.filename))
if os.path.isfile(target):
raise ErrorException('Cannot upload {target} as it already exists'.format( # noqa: E501

View File

@ -18,7 +18,7 @@ class BrickInstructionsList(object):
sets_total: int
unknown_total: int
def __init__(self, /, force=False):
def __init__(self, /, *, force=False):
# Load instructions only if there is none already loaded
all = getattr(self, 'all', None)

View File

@ -23,6 +23,7 @@ class BrickMinifigure(BrickRecord):
def __init__(
self,
/,
*,
brickset: 'BrickSet | None' = None,
record: Row | dict[str, Any] | None = None,
):
@ -149,6 +150,7 @@ class BrickMinifigure(BrickRecord):
def from_rebrickable(
data: dict[str, Any],
/,
*,
brickset: 'BrickSet | None' = None,
**_,
) -> dict[str, Any]:

View File

@ -42,7 +42,7 @@ class BrickMinifigureList(BrickRecordList[BrickMinifigure]):
return self
# Last added minifigure
def last(self, /, limit: int = 6) -> Self:
def last(self, /, *, limit: int = 6) -> Self:
# Randomize
if current_app.config['RANDOM']:
order = 'RANDOM()'
@ -89,6 +89,7 @@ class BrickMinifigureList(BrickRecordList[BrickMinifigure]):
part_num: str,
color_id: int,
/,
*,
element_id: int | None = None,
) -> Self:
# Save the parameters to the fields
@ -113,6 +114,7 @@ class BrickMinifigureList(BrickRecordList[BrickMinifigure]):
part_num: str,
color_id: int,
/,
*,
element_id: int | None = None,
) -> Self:
# Save the parameters to the fields

View File

@ -27,6 +27,7 @@ class BrickPart(BrickRecord):
def __init__(
self,
/,
*,
brickset: 'BrickSet | None' = None,
minifigure: 'BrickMinifigure | None' = None,
record: Row | dict[str, Any] | None = None,
@ -83,6 +84,7 @@ class BrickPart(BrickRecord):
part_num: str,
color_id: int,
/,
*,
element_id: int | None = None
) -> Self:
# Save the parameters to the fields
@ -112,6 +114,7 @@ class BrickPart(BrickRecord):
brickset: 'BrickSet',
id: str,
/,
*,
minifigure: 'BrickMinifigure | None' = None,
) -> Self:
# Save the parameters to the fields
@ -250,6 +253,7 @@ class BrickPart(BrickRecord):
def from_rebrickable(
data: dict[str, Any],
/,
*,
brickset: 'BrickSet | None' = None,
minifigure: 'BrickMinifigure | None' = None,
**_,

View File

@ -49,6 +49,7 @@ class BrickPartList(BrickRecordList[BrickPart]):
self,
brickset: 'BrickSet',
/,
*,
minifigure: 'BrickMinifigure | None' = None,
) -> Self:
# Save the brickset and minifigure

View File

@ -34,6 +34,7 @@ class Rebrickable(Generic[T]):
number: str,
model: Type[T],
/,
*,
socket: 'BrickSocket | None' = None,
brickset: 'BrickSet | None' = None,
minifigure: 'BrickMinifigure | None' = None
@ -113,7 +114,7 @@ class Rebrickable(Generic[T]):
return results
# Load from the API
def load(self, /, parameters: dict[str, Any] = {}) -> dict[str, Any]:
def load(self, /, *, parameters: dict[str, Any] = {}) -> dict[str, Any]:
# Inject the API key
parameters['api_key'] = current_app.config['REBRICKABLE_API_KEY']

View File

@ -25,6 +25,7 @@ class RebrickableImage(object):
self,
brickset: 'BrickSet',
/,
*,
minifigure: 'BrickMinifigure | None' = None,
part: 'BrickPart | None' = None,
):

View File

@ -29,6 +29,7 @@ class RebrickableParts(object):
socket: 'BrickSocket',
brickset: 'BrickSet',
/,
*,
minifigure: 'BrickMinifigure | None' = None,
):
# Save the socket

View File

@ -104,6 +104,7 @@ class RebrickableSet(object):
self,
data: dict[str, Any],
/,
*,
from_download=False,
) -> BrickSet | None:
# Reset the progress

View File

@ -24,7 +24,7 @@ class BrickRecord(object):
# Insert into the database
# If we do not commit immediately, we defer the execute() call
def insert(self, /, commit=True) -> None:
def insert(self, /, *, commit=True) -> None:
database = BrickSQL()
rows, q = database.execute(
self.insert_query,
@ -40,7 +40,7 @@ class BrickRecord(object):
return self.fields.__dict__.items()
# Get from the database using the query
def select(self, /, override_query: str | None = None) -> Row | None:
def select(self, /, *, override_query: str | None = None) -> Row | None:
if override_query:
query = override_query
else:

View File

@ -32,6 +32,7 @@ class BrickRecordList(Generic[T]):
def select(
self,
/,
*,
override_query: str | None = None,
order: str | None = None,
limit: int | None = None,

View File

@ -22,7 +22,7 @@ class BrickRetiredList(object):
size: int | None
exception: Exception | None
def __init__(self, /, force: bool = False):
def __init__(self, /, *, force: bool = False):
# Load sets only if there is none already loaded
retired = getattr(self, 'retired', None)

View File

@ -26,6 +26,7 @@ class BrickSet(BrickRecord):
def __init__(
self,
/,
*,
record: Row | dict[str, Any] | None = None,
):
super().__init__()

View File

@ -58,7 +58,7 @@ class BrickSetList(BrickRecordList[BrickSet]):
return self
# Last added sets
def last(self, /, limit: int = 6) -> Self:
def last(self, /, *, limit: int = 6) -> Self:
# Randomize
if current_app.config['RANDOM']:
order = 'RANDOM()'
@ -76,7 +76,7 @@ class BrickSetList(BrickRecordList[BrickSet]):
def missing_minifigure(
self,
fig_num: str,
/,
/
) -> Self:
# Save the parameters to the fields
self.fields.fig_num = fig_num
@ -98,6 +98,7 @@ class BrickSetList(BrickRecordList[BrickSet]):
part_num: str,
color_id: int,
/,
*,
element_id: int | None = None,
) -> Self:
# Save the parameters to the fields
@ -120,7 +121,7 @@ class BrickSetList(BrickRecordList[BrickSet]):
def using_minifigure(
self,
fig_num: str,
/,
/
) -> Self:
# Save the parameters to the fields
self.fields.fig_num = fig_num
@ -142,6 +143,7 @@ class BrickSetList(BrickRecordList[BrickSet]):
part_num: str,
color_id: int,
/,
*,
element_id: int | None = None,
) -> Self:
# Save the parameters to the fields

View File

@ -140,6 +140,7 @@ class BrickSocket(object):
def auto_progress(
self,
/,
*,
message: str | None = None,
increment_total=False,
) -> None:
@ -203,7 +204,7 @@ class BrickSocket(object):
sql_close()
# Update the progress
def progress(self, /, message: str | None = None) -> None:
def progress(self, /, *, message: str | None = None) -> None:
# Save the las message
if message is not None:
self.progress_message = message
@ -218,14 +219,14 @@ class BrickSocket(object):
self.emit('PROGRESS', data)
# Update the progress total only
def update_total(self, total: int, /, add: bool = False) -> None:
def update_total(self, total: int, /, *, add: bool = False) -> None:
if add:
self.progress_total += total
else:
self.progress_total = total
# Update the total
def total_progress(self, total: int, /, add: bool = False) -> None:
def total_progress(self, total: int, /, *, add: bool = False) -> None:
self.update_total(total, add=add)
self.progress()

View File

@ -35,7 +35,7 @@ class BrickSQL(object):
stats: BrickSQLStats
version: int
def __init__(self, /, failsafe: bool = False):
def __init__(self, /, *, failsafe: bool = False):
# Instantiate the database connection in the Flask
# application context so that it can be used by all
# requests without re-opening connections
@ -147,9 +147,10 @@ class BrickSQL(object):
self,
query: str,
/,
*,
parameters: dict[str, Any] = {},
defer: bool = False,
**context,
**context: Any,
) -> Tuple[int, str]:
# Stats: execute
self.stats.execute += 1
@ -172,7 +173,7 @@ class BrickSQL(object):
return result.rowcount, query
# Shorthand to executescript
def executescript(self, query: str, /, **context) -> None:
def executescript(self, query: str, /, **context: Any) -> None:
# Load the query
query = self.load_query(query, **context)
@ -187,8 +188,9 @@ class BrickSQL(object):
self,
query: str,
/,
*,
parameters: dict[str, Any] = {},
**context,
**context: Any,
) -> Tuple[int, str]:
rows, query = self.execute(query, parameters=parameters, **context)
self.commit()
@ -200,8 +202,9 @@ class BrickSQL(object):
self,
query: str,
/,
*,
parameters: dict[str, Any] = {},
**context,
**context: Any,
) -> list[sqlite3.Row]:
_, query = self.execute(query, parameters=parameters, **context)
@ -221,8 +224,9 @@ class BrickSQL(object):
self,
query: str,
/,
*,
parameters: dict[str, Any] = {},
**context,
**context: Any,
) -> sqlite3.Row | None:
_, query = self.execute(query, parameters=parameters, **context)
@ -245,7 +249,7 @@ class BrickSQL(object):
return defer
# Load a query by name
def load_query(self, name: str, /, **context) -> str:
def load_query(self, name: str, /, **context: Any) -> str:
# Grab the existing environment if it exists
environment = getattr(g, G_ENVIRONMENT, None)
@ -276,7 +280,7 @@ class BrickSQL(object):
self,
query: str,
parameters: dict[str, Any],
/,
/
) -> sqlite3.Cursor:
logger.debug('SQLite3: execute: {query}'.format(
query=BrickSQL.clean_query(query)

View File

@ -4,7 +4,7 @@ class BrickCounter(object):
icon: str
count: int
def __init__(self, name: str, table: str, /, icon: str = ''):
def __init__(self, name: str, table: str, /, *, icon: str = ''):
self.name = name
self.table = table
self.icon = icon

View File

@ -22,7 +22,7 @@ class BrickThemeList(object):
size: int | None
exception: Exception | None
def __init__(self, /, force: bool = False):
def __init__(self, /, *, force: bool = False):
# Load themes only if there is none already loaded
themes = getattr(self, 'themes', None)

View File

@ -17,6 +17,7 @@ class BrickWish(BrickSet):
def __init__(
self,
/,
*,
record: Row | dict[str, Any] | None = None,
):
# Don't init BrickSet, init the parent of BrickSet directly