Skip to content
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

Yet more cleanup (Sourcery refactored) #33

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions dbkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ def __delattr__(self, key):
raise AttributeError(f"Unknown field: {key}") from exc

def __repr__(self):
return "<AttrDict " + dict.__repr__(self) + ">"
return f"<AttrDict {dict.__repr__(self)}>"
Copy link
Author

Choose a reason for hiding this comment

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

Function AttrDict.__repr__ refactored with the following changes:



def _ping(cursor):
Expand All @@ -921,17 +921,15 @@ def _safe_close(obj):
Call the close method on an object safely.
"""
# pylint: disable-msg=W0702
try:
with contextlib.suppress(Exception):
obj.close()
except Exception: # pragma: no cover
pass
Comment on lines -924 to -927
Copy link
Author

Choose a reason for hiding this comment

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

Function _safe_close refactored with the following changes:

This removes the following comments ( why? ):

# pragma: no cover



def to_dict(key, resultset):
"""
Convert a resultset into a dictionary keyed off of one of its columns.
"""
return dict((row[key], row) for row in resultset)
return {row[key]: row for row in resultset}
Comment on lines -934 to +932
Copy link
Author

Choose a reason for hiding this comment

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

Function to_dict refactored with the following changes:



def make_placeholders(seq, start=1):
Expand All @@ -955,8 +953,7 @@ def make_placeholders(seq, start=1):
)
if placeholders is None:
raise NotSupportedError(
"Param style '%s' does not support sequence type '%s'"
% (param_style, seq.__class__.__name__)
f"Param style '{param_style}' does not support sequence type '{seq.__class__.__name__}'"
Comment on lines -958 to +956
Copy link
Author

Choose a reason for hiding this comment

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

Function make_placeholders refactored with the following changes:

)
return ", ".join(placeholders)

Expand Down
4 changes: 1 addition & 3 deletions tests/test_dbkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,9 @@ def test_context(self):
self.assertTrue(dbkit.Context.current(with_exception=False) is ctx)
self.assertTrue(ctx.mdr is not None)
ctx.close()
try:
with contextlib.suppress(Exception):
dbkit.context()
self.fail("Should not have been able to access context.")
except Exception:
pass
Comment on lines -63 to -67
Copy link
Author

Choose a reason for hiding this comment

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

Function TestBasics.test_context refactored with the following changes:

self.assertTrue(ctx.mdr is None)
self.assertEqual(len(ctx.stack), 0)

Expand Down