-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery Starbot ⭐ refactored ahmadfikrimasyhur/flask-admin #1
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to GitHub API limits, only the first 60 comments can be shown.
tmp_email = first_names[i].lower() + "." + last_names[i].lower() + "@example.com" | ||
tmp_pass = ''.join(random.choice(string.ascii_lowercase + string.digits) for i in range(10)) | ||
tmp_email = f"{first_names[i].lower()}.{last_names[i].lower()}@example.com" | ||
tmp_pass = ''.join( | ||
random.choice(string.ascii_lowercase + string.digits) | ||
for _ in range(10) | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function build_sample_db
refactored with the following changes:
- Use f-string instead of string concatenation [×3] (
use-fstring-for-concatenation
) - Replace unused for index with underscore (
for-index-underscore
)
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + DATABASE_FILE | ||
SQLALCHEMY_DATABASE_URI = f'sqlite:///{DATABASE_FILE}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 6-6
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
if not login.current_user.is_authenticated: | ||
return redirect(url_for('.login_view')) | ||
return super(MyAdminIndexView, self).index() | ||
return ( | ||
super(MyAdminIndexView, self).index() | ||
if login.current_user.is_authenticated | ||
else redirect(url_for('.login_view')) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function MyAdminIndexView.index
refactored with the following changes:
- Swap if/else branches of if expression to remove negation (
swap-if-expression
) - Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
user.email = user.login + "@example.com" | ||
user.password = generate_password_hash(''.join(random.choice(string.ascii_lowercase + string.digits) for i in range(10))) | ||
user.email = f"{user.login}@example.com" | ||
user.password = generate_password_hash( | ||
''.join( | ||
random.choice(string.ascii_lowercase + string.digits) | ||
for _ in range(10) | ||
) | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function build_sample_db
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Replace unused for index with underscore (
for-index-underscore
)
override = request.args.get('lang') | ||
|
||
if override: | ||
if override := request.args.get('lang'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_locale
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
user.email = first_names[i].lower() + "@example.com" | ||
user.email = f"{first_names[i].lower()}@example.com" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function build_sample_db
refactored with the following changes:
- Use f-string instead of string concatenation [×3] (
use-fstring-for-concatenation
) - Replace call to format with f-string (
use-fstring-for-formatting
)
tmp = u""" | ||
return u""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function index
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
return Markup("<nobr>{}</nobr>".format(model.phone_number)) if model.phone_number else None | ||
return ( | ||
Markup(f"<nobr>{model.phone_number}</nobr>") | ||
if model.phone_number | ||
else None | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function phone_number_formatter
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
return "+{} ({}) {} {} {}".format(self.dialling_code, number[0], number[1:3], number[3:6], number[6::]) | ||
return f"+{self.dialling_code} ({number[0]}) {number[1:3]} {number[3:6]} {number[6::]}" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function User.phone_number
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
def phone_number(cls): | ||
return sql.operators.ColumnOperators.concat(cast(cls.dialling_code, db.String), cls.local_phone_number) | ||
def phone_number(self): | ||
return sql.operators.ColumnOperators.concat( | ||
cast(self.dialling_code, db.String), self.local_phone_number | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function User.phone_number
refactored with the following changes:
- The first argument to instance methods should be
self
(instance-method-first-arg-name
)
return "{}, {}".format(self.last_name, self.first_name) | ||
return f"{self.last_name}, {self.first_name}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function User.__str__
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
return "{}: {}".format(self.id, self.__str__()) | ||
return f"{self.id}: {self.__str__()}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function User.__repr__
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
return "{}".format(self.title) | ||
return f"{self.title}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Post.__str__
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
return "{}".format(self.name) | ||
return f"{self.name}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Tag.__str__
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
return "{}".format(self.name) | ||
return f"{self.name}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Tree.__str__
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
def __init__(cls, classname, bases, fields): | ||
type.__init__(cls, classname, bases, fields) | ||
def __init__(self, classname, bases, fields): | ||
type.__init__(self, classname, bases, fields) | ||
|
||
# Gather exposed views | ||
cls._urls = [] | ||
cls._default_view = None | ||
self._urls = [] | ||
self._default_view = None | ||
|
||
for p in dir(cls): | ||
attr = getattr(cls, p) | ||
for p in dir(self): | ||
attr = getattr(self, p) | ||
|
||
if hasattr(attr, '_urls'): | ||
# Collect methods | ||
for url, methods in attr._urls: | ||
cls._urls.append((url, p, methods)) | ||
self._urls.append((url, p, methods)) | ||
|
||
if url == '/': | ||
cls._default_view = p | ||
self._default_view = p | ||
|
||
# Wrap views | ||
setattr(cls, p, _wrap_view(attr)) | ||
setattr(self, p, _wrap_view(attr)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function AdminViewMeta.__init__
refactored with the following changes:
- The first argument to instance methods should be
self
(instance-method-first-arg-name
)
raise Exception(u'Attempted to instantiate admin view %s without default view' % self.__class__.__name__) | ||
raise Exception( | ||
f'Attempted to instantiate admin view {self.__class__.__name__} without default view' | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function BaseView.__init__
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
if endpoint: | ||
return endpoint | ||
|
||
return self.__class__.__name__.lower() | ||
return endpoint or self.__class__.__name__.lower() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function BaseView._get_endpoint
refactored with the following changes:
- Simplify if expression by using or (
or-if-exp-identity
) - Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
if admin.url != '/': | ||
url = '%s/%s' % (admin.url, self.endpoint) | ||
if admin.url == '/': | ||
url = '/' if self == admin.index_view else f'/{self.endpoint}' | ||
else: | ||
if self == admin.index_view: | ||
url = '/' | ||
else: | ||
url = '/%s' % self.endpoint | ||
else: | ||
if not url.startswith('/'): | ||
url = '%s/%s' % (admin.url, url) | ||
url = f'{admin.url}/{self.endpoint}' | ||
elif not url.startswith('/'): | ||
url = f'{admin.url}/{url}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function BaseView._get_view_url
refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif
) - Swap if/else branches (
swap-if-else-branches
) - Replace interpolated string formatting with f-string [×3] (
replace-interpolation-with-fstring
) - Replace if statement with if expression (
assign-if-exp
)
if not self.admin or not self.admin.app: | ||
return False | ||
|
||
return self.admin.app.debug | ||
return False if not self.admin or not self.admin.app else self.admin.app.debug |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function BaseView._debug
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
self._menu_categories = dict() | ||
self._menu_categories = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Admin.__init__
refactored with the following changes:
- Replace dict() with {} (
dict-literal
)
self.app.extensions = dict() | ||
self.app.extensions = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Admin._init_extension
refactored with the following changes:
- Replace dict() with {} (
dict-literal
)
for validator in field.validators: | ||
if isinstance(validator, (DataRequired, InputRequired, FieldListInputRequired)): | ||
return True | ||
return False | ||
return any( | ||
isinstance( | ||
validator, (DataRequired, InputRequired, FieldListInputRequired) | ||
) | ||
for validator in field.validators | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function is_required_form_field
refactored with the following changes:
- Use any() instead of for loop (
use-any
)
errors = form[field_name].label.text + u": " + u", ".join(errors) | ||
errors = f"{form[field_name].label.text}: " + u", ".join(errors) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function flash_errors
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
for c in self._children: | ||
if c.is_active(view): | ||
return True | ||
|
||
return False | ||
return any(c.is_active(view) for c in self._children) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function BaseMenu.is_active
refactored with the following changes:
- Use any() instead of for loop (
use-any
)
return self._error('Cli: %s' % err) | ||
return self._error(f'Cli: {err}') | ||
except Exception as ex: | ||
log.exception(ex) | ||
return self._error('Cli: %s' % ex) | ||
return self._error(f'Cli: {ex}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function RedisCli.execute_view
refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring
)
form_class = wt_ndb.model_form( | ||
return wt_ndb.model_form( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NdbModelView.scaffold_form
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
result = create_editable_list_form(Form, form_class, widget) | ||
return result | ||
return create_editable_list_form(Form, form_class, widget) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NdbModelView.scaffold_list_form
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
sort_field = "-" + sort_field | ||
sort_field = f"-{sort_field}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function DbModelView.get_list
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
raise ValueError("Unsupported model: %s" % model) | ||
raise ValueError(f"Unsupported model: {model}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function ModelView
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨
Here's your pull request refactoring your most popular Python repo.
If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.
Review changes via command line
To manually merge these changes, make sure you're on the
master
branch, then run: