Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
bryannho committed Jan 26, 2024
1 parent 5c7ba0e commit 5c4fb47
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
13 changes: 7 additions & 6 deletions src/sql/connection/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,16 +832,17 @@ def raw_execute(self, query, parameters=None, with_=None):
named_params_ = ", ".join(named_params)
e.add_detail(
f"Your query contains named parameters ({named_params_}) "
"but the named parameters feature is \"warn\". \nEnable it "
"with: %config SqlMagic.named_parameters=\"enabled\" \nor "
"disable it with: %config SqlMagic.named_parameters=\"disabled\"\n"
'but the named parameters feature is "warn". \nEnable it '
'with: %config SqlMagic.named_parameters="enabled" \nor '
'disable it with: '
'%config SqlMagic.named_parameters="disabled"\n'
"For more info, see the docs: "
"https://jupysql.ploomber.io/en/latest/api/configuration.html"
"https://jupysql.ploomber.io/en/latest/api/configuration.html" # noqa
)
elif parameters == {}:
e.add_detail(
"The named parameters feature is \"disabled\". "
"Enable it with: %config SqlMagic.named_parameters=\"enabled\".\n"
'The named parameters feature is "disabled". '
'Enable it with: %config SqlMagic.named_parameters="enabled".\n'
"For more info, see the docs: "
"https://jupysql.ploomber.io/en/latest/api/configuration.html"
)
Expand Down
7 changes: 1 addition & 6 deletions src/sql/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,12 +579,7 @@ def interactive_execute_wrapper(**kwargs):
parameters = user_ns

try:
result = run_statements(
conn,
command.sql,
self,
parameters=parameters
)
result = run_statements(conn, command.sql, self, parameters=parameters)

if (
result is not None
Expand Down
35 changes: 24 additions & 11 deletions src/sql/trait.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,52 @@
import warnings

VALUE_WARNING = (
"Please use a valid option: \"warn\", \"enabled\", or \"disabled\". \n"
"For more information, see the docs: https://jupysql.ploomber.io/en/latest/api/configuration.html"
'Please use a valid option: "warn", "enabled", or "disabled". \n'
"For more information, "
"see the docs: https://jupysql.ploomber.io/en/latest/api/configuration.html"
)

class Parameters(TraitType):

class Parameters(TraitType):
def __init__(self, **kwargs):
super(Parameters, self).__init__(**kwargs)

def validate(self, obj, value):
if isinstance(value, bool):
if value == True:
warnings.warn(f"named_parameters: boolean values are now deprecated. Value {value} will be treated as \"enabled\". \n{VALUE_WARNING}", FutureWarning)
if value:
warnings.warn(
'named_parameters: boolean values are now deprecated. '
f'Value {value} will be treated as "enabled". \n'
f'{VALUE_WARNING}',
FutureWarning,
)
return "enabled"
else:
warnings.warn(f"named_parameters: boolean values are now deprecated. Value {value} will be treated as \"warn\" (default). \n{VALUE_WARNING}", FutureWarning)
warnings.warn(
'named_parameters: boolean values are now deprecated. '
f'Value {value} will be treated as "warn" (default). \n'
f'{VALUE_WARNING}',
FutureWarning,
)
return "warn"
elif isinstance(value, str):
if not value:
display.message(f"named_parameters: Value \"\" will be treated as \"warn\" (default)")
display.message(
'named_parameters: Value "" will be treated as "warn" (default)'
)
return "warn"

value = value.lower()
if value not in ("warn", "enabled", "disabled"):
raise TraitError(
f"{value} is not a valid option for named_parameters. "
f"Valid options are: \"warn\", \"enabled\", or \"disabled\"."
f'Valid options are: "warn", "enabled", or "disabled".'
)

return value

else:
raise TraitError(
f"{value} is not a valid option for named_parameters. "
f"Valid options are: \"warn\", \"enabled\", or \"disabled\"."
)
f"{value} is not a valid option for named_parameters. "
f'Valid options are: "warn", "enabled", or "disabled".'
)

0 comments on commit 5c4fb47

Please sign in to comment.