-
Notifications
You must be signed in to change notification settings - Fork 1
Sourcery Starbot ⭐ refactored sudharsan2020/python-mastery #2
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
base: main
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.
def csv_record(fields): | ||
s = '"%s",%0.2f,"%s","%s",%0.2f,%0.2f,%0.2f,%0.2f,%d' % tuple(fields) | ||
return s | ||
return '"%s",%0.2f,"%s","%s",%0.2f,%0.2f,%0.2f,%0.2f,%d' % tuple(fields) |
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 csv_record
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
|
||
def draw(rows, columns): | ||
for r in range(rows): | ||
for _ in range(rows): |
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 draw
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
if True: | ||
# Part (b) | ||
import reader | ||
rows = reader.read_csv_as_dicts('../../Data/ctabus.csv', | ||
[sys.intern, sys.intern, sys.intern, int]) | ||
else: | ||
# Part (d) - Challenge | ||
import colreader | ||
rows = colreader.read_csv_as_columns('../../Data/ctabus.csv', | ||
[sys.intern, sys.intern, sys.intern, int]) | ||
|
||
# -------------------------------------------------- | ||
# Question 1: How many bus routes are in Chicago? | ||
# Solution: Use a set to get unique values. | ||
|
||
routes = set() | ||
for row in rows: | ||
routes.add(row['route']) | ||
# Part (b) | ||
import reader | ||
rows = reader.read_csv_as_dicts('../../Data/ctabus.csv', | ||
[sys.intern, sys.intern, sys.intern, int]) | ||
routes = {row['route'] for row in rows} |
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 10-27
refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if
) - Convert for loop into set comprehension (
set-comprehension
)
This removes the following comments ( why? ):
# Part (d) - Challenge
# --------------------------------------------------
# Question 1: How many bus routes are in Chicago?
# Solution: Use a set to get unique values.
headers = next(rows) | ||
for row in rows: | ||
records.append(cls.from_row(row)) | ||
records.extend(cls.from_row(row) for row in rows) |
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 read_csv_as_instances
refactored with the following changes:
- Replace a for append loop with list extend (
for-append-to-extend
)
headers = next(rows) | ||
for row in rows: | ||
records.append(cls.from_row(row)) | ||
records.extend(cls.from_row(row) for row in rows) |
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 read_csv_as_instances
refactored with the following changes:
- Replace a for append loop with list extend (
for-append-to-extend
)
print('<tr>', end=' ') | ||
for h in headers: | ||
print('<th>%s</th>' % h, end=' ') | ||
print(f'<th>{h}</th>', end=' ') |
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 HTMLTableFormatter.headings
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
print('<tr>', end=' ') | ||
for d in rowdata: | ||
print('<td>%s</td>' % d, end=' ') | ||
print(f'<td>{d}</td>', end=' ') |
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 HTMLTableFormatter.row
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
formatter_cls = HTMLTableFormatter | ||
else: | ||
raise RuntimeError('Unknown format %s' % name) | ||
raise RuntimeError(f'Unknown format {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 create_formatter
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
|
||
def typedproperty(name, expected_type): | ||
private_name = '_' + name | ||
private_name = f'_{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 typedproperty
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
super().__setattr__(name, value) | ||
else: | ||
raise AttributeError('No attribute %s' % name) | ||
raise AttributeError(f'No attribute {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 Structure.__setattr__
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
def __repr__(self): | ||
return '%s(%s)' % (type(self).__name__, | ||
', '.join(repr(getattr(self, name)) for name in self._fields)) | ||
return f"{type(self).__name__}({', '.join(repr(getattr(self, name)) for name in self._fields)})" |
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 Structure.__repr__
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
super().__setattr__(name, value) | ||
else: | ||
raise AttributeError('No attribute %s' % name) | ||
raise AttributeError(f'No attribute {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 Structure.__setattr__
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
def __repr__(self): | ||
return '%s(%s)' % (type(self).__name__, | ||
', '.join(repr(getattr(self, name)) for name in self._fields)) | ||
return f"{type(self).__name__}({', '.join(repr(getattr(self, name)) for name in self._fields)})" |
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 Structure.__repr__
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
super().__setattr__(name, value) | ||
else: | ||
raise AttributeError('No attribute %s' % name) | ||
raise AttributeError(f'No attribute {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 Structure.__setattr__
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
def __repr__(self): | ||
return '%s(%s)' % (type(self).__name__, | ||
', '.join(repr(getattr(self, name)) for name in self._fields)) | ||
return f"{type(self).__name__}({', '.join(repr(getattr(self, name)) for name in self._fields)})" |
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 Structure.__repr__
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
class StructureMeta(type): | ||
@classmethod | ||
def __prepare__(meta, clsname, bases): | ||
def __prepare__(cls, clsname, bases): |
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 StructureMeta.__prepare__
refactored with the following changes:
- The first argument to class methods should be
cls
(class-method-first-arg-name
)
def __new__(meta, name, bases, methods): | ||
def __new__(cls, name, bases, methods): | ||
methods = methods.maps[0] | ||
return super().__new__(meta, name, bases, methods) | ||
return super().__new__(cls, name, bases, methods) |
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 StructureMeta.__new__
refactored with the following changes:
- The first argument to class methods should be
cls
(class-method-first-arg-name
)
super().__setattr__(name, value) | ||
else: | ||
raise AttributeError('No attribute %s' % name) | ||
raise AttributeError(f'No attribute {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 Structure.__setattr__
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
def __repr__(self): | ||
return '%s(%s)' % (type(self).__name__, | ||
', '.join(repr(getattr(self, name)) for name in self._fields)) | ||
return f"{type(self).__name__}({', '.join(repr(getattr(self, name)) for name in self._fields)})" |
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 Structure.__repr__
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
cls._fields = tuple([v.name for v in validators]) | ||
cls._fields = tuple(v.name for v in validators) | ||
|
||
# Collect type conversions. The lambda x:x is an identity | ||
# function that's used in case no expected_type is found. | ||
cls._types = tuple([ getattr(v, 'expected_type', lambda x: x) | ||
for v in validators ]) | ||
cls._types = tuple( | ||
getattr(v, 'expected_type', lambda x: x) for v in validators | ||
) | ||
|
||
# Create the __init__ method | ||
if cls._fields: | ||
cls.create_init() | ||
|
||
|
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 validate_attributes
refactored with the following changes:
- Replace unneeded comprehension with generator [×2] (
comprehension-to-generator
)
def typed_structure(clsname, **validators): | ||
cls = type(clsname, (Structure,), validators) | ||
return cls | ||
return type(clsname, (Structure,), 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 typed_structure
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
print('<tr>', end=' ') | ||
for h in headers: | ||
print('<th>%s</th>' % h, end=' ') | ||
print(f'<th>{h}</th>', end=' ') |
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 HTMLTableFormatter.headings
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
print('<tr>', end=' ') | ||
for d in rowdata: | ||
print('<td>%s</td>' % d, end=' ') | ||
print(f'<td>{d}</td>', end=' ') |
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 HTMLTableFormatter.row
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
formatter_cls = HTMLTableFormatter | ||
else: | ||
raise RuntimeError('Unknown format %s' % name) | ||
raise RuntimeError(f'Unknown format {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 create_formatter
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
class StructureMeta(type): | ||
@classmethod | ||
def __prepare__(meta, clsname, bases): | ||
def __prepare__(cls, clsname, bases): |
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 StructureMeta.__prepare__
refactored with the following changes:
- The first argument to class methods should be
cls
(class-method-first-arg-name
)
def typed_structure(clsname, **validators): | ||
cls = type(clsname, (Structure,), validators) | ||
return cls | ||
return type(clsname, (Structure,), 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 typed_structure
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
print('<tr>', end=' ') | ||
for h in headers: | ||
print('<th>%s</th>' % h, end=' ') | ||
print(f'<th>{h}</th>', end=' ') |
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 HTMLTableFormatter.headings
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
print('<tr>', end=' ') | ||
for d in rowdata: | ||
print('<td>%s</td>' % d, end=' ') | ||
print(f'<td>{d}</td>', end=' ') |
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 HTMLTableFormatter.row
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
formatter_cls = HTMLTableFormatter | ||
else: | ||
raise RuntimeError('Unknown format %s' % name) | ||
raise RuntimeError(f'Unknown format {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 create_formatter
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
class StructureMeta(type): | ||
@classmethod | ||
def __prepare__(meta, clsname, bases): | ||
def __prepare__(cls, clsname, bases): |
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 StructureMeta.__prepare__
refactored with the following changes:
- The first argument to class methods should be
cls
(class-method-first-arg-name
)
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
main
branch, then run: