Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Jun 24, 2022

Pull Request #2 refactored by Sourcery.

Since the original Pull Request was opened as a fork in a contributor's
repository, we are unable to create a Pull Request branching from it.

To incorporate these changes, you can either:

  1. Merge this Pull Request instead of the original, or

  2. Ask your contributor to locally incorporate these commits and push them to
    the original Pull Request

    Incorporate changes via command line
    git fetch https://github.com/synodriver/sqlmodel pull/2/head
    git merge --ff-only FETCH_HEAD
    git push

NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from synodriver June 24, 2022 07:28
Comment on lines -207 to -214
relationship_info = RelationshipInfo(
return RelationshipInfo(
back_populates=back_populates,
link_model=link_model,
sa_relationship=sa_relationship,
sa_relationship_args=sa_relationship_args,
sa_relationship_kwargs=sa_relationship_kwargs,
)
return relationship_info
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Relationship refactored with the following changes:

Comment on lines -331 to +330
def __init__(
cls, classname: str, bases: Tuple[type, ...], dict_: Dict[str, Any], **kw: Any
) -> None:
def __init__(self, classname: str, bases: Tuple[type, ...], dict_: Dict[str, Any], **kw: Any) -> None:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SQLModelMetaclass.__init__ refactored with the following changes:

This removes the following comments ( why? ):

# Fix #315

if issubclass(field.type_, BaseModel) and field.type_.__custom_root_type__:
return get_pydantic_root_model_engine_type(
get_sqlachemy_type(field.type_.__fields__["__root__"]), field.type_
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_sqlachemy_type refactored with the following changes:

Comment on lines -508 to +504
kwargs.update(cast(Dict[Any, Any], sa_column_kwargs))
kwargs |= cast(Dict[Any, Any], sa_column_kwargs)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_column_from_field refactored with the following changes:

Comment on lines -573 to +572
if getattr(self.__config__, "table", False):
if is_instrumented(self, name):
set_attribute(self, name, value)
if getattr(self.__config__, "table", False) and is_instrumented(
self, name
):
set_attribute(self, name, value)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SQLModel.__setattr__ refactored with the following changes:

Comment on lines -665 to +656
if include is None and exclude is None and exclude_unset is False:
if include is None and exclude is None and not exclude_unset:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SQLModel._calculate_keys refactored with the following changes:

This removes the following comments ( why? ):

# Do not include relationships as that would easily lead to infinite
# recursion, or traversing the whole database
# | self.__sqlmodel_relationships__.keys()
# Original in Pydantic:
# keys = self.__dict__.keys()
# Updated to not return SQLAlchemy attributes

Comment on lines -696 to +679
def __tablename__(cls) -> str:
return cls.__name__.lower()
def __tablename__(self) -> str:
return self.__name__.lower()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SQLModel.__tablename__ refactored with the following changes:

Comment on lines -20 to +21
sql_str = str(dialect).rstrip()
if sql_str:
print(sql_str + ";")
if sql_str := str(dialect).rstrip():
print(f"{sql_str};")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function pg_dump refactored with the following changes:

if sql_str:
print(sql_str + ";")
if sql_str := str(dialect).rstrip():
print(f"{sql_str};")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function sqlite_dump refactored with the following changes:

Comment on lines -20 to +34
str("Hero"),
float(0.5),
int(5),
datetime(year=2020, month=2, day=2, hour=2, minute=2, second=2, microsecond=2),
"Hero",
0.5,
5,
datetime(
year=2020, month=2, day=2, hour=2, minute=2, second=2, microsecond=2
),
date(year=2020, month=2, day=2),
timedelta(
days=2, seconds=2, microseconds=2, milliseconds=2, minutes=2, hours=2, weeks=2
days=2,
seconds=2,
microseconds=2,
milliseconds=2,
minutes=2,
hours=2,
weeks=2,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 20-26 refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Jun 24, 2022

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.04%.

Quality metrics Before After Change
Complexity 10.94 🙂 10.82 🙂 -0.12 👍
Method Length 69.46 🙂 69.00 🙂 -0.46 👍
Working memory 9.13 🙂 9.18 🙂 0.05 👎
Quality 60.42% 🙂 60.38% 🙂 -0.04% 👎
Other metrics Before After Change
Lines 889 877 -12
Changed files Quality Before Quality After Quality Change
sqlmodel/main.py 55.33% 🙂 55.34% 🙂 0.01% 👍
tests/test_enums.py 80.34% ⭐ 79.98% ⭐ -0.36% 👎
tests/test_types.py 77.28% ⭐ 77.35% ⭐ 0.07% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
sqlmodel/main.py SQLModelMetaclass.__init__ 33 ⛔ 222 ⛔ 16 ⛔ 22.64% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
sqlmodel/main.py SQLModelMetaclass.__new__ 20 😞 294 ⛔ 14 😞 28.90% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
sqlmodel/main.py get_column_from_field 15 🙂 231 ⛔ 12 😞 38.63% 😞 Try splitting into smaller methods. Extract out complex expressions
sqlmodel/main.py Field 1 ⭐ 132 😞 33 ⛔ 48.07% 😞 Try splitting into smaller methods. Extract out complex expressions
sqlmodel/main.py create_model 12 🙂 112 🙂 13 😞 50.69% 🙂 Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant