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__( def __init__(
self, self,
/, /,
*,
n: str, n: str,
e: str | None = None, e: str | None = None,
d: Any = None, d: Any = None,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -24,7 +24,7 @@ class BrickRecord(object):
# Insert into the database # Insert into the database
# If we do not commit immediately, we defer the execute() call # 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() database = BrickSQL()
rows, q = database.execute( rows, q = database.execute(
self.insert_query, self.insert_query,
@ -40,7 +40,7 @@ class BrickRecord(object):
return self.fields.__dict__.items() return self.fields.__dict__.items()
# Get from the database using the query # 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: if override_query:
query = override_query query = override_query
else: else:

View File

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

View File

@ -22,7 +22,7 @@ class BrickRetiredList(object):
size: int | None size: int | None
exception: Exception | 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 # Load sets only if there is none already loaded
retired = getattr(self, 'retired', None) retired = getattr(self, 'retired', None)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -22,7 +22,7 @@ class BrickThemeList(object):
size: int | None size: int | None
exception: Exception | 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 # Load themes only if there is none already loaded
themes = getattr(self, 'themes', None) themes = getattr(self, 'themes', None)

View File

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