Skip to content

Conversation

SourceryAI
Copy link

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:

git fetch https://github.com/sourcery-ai-bot/python-mastery main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Copy link
Author

@SourceryAI SourceryAI left a 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)
Copy link
Author

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:


def draw(rows, columns):
for r in range(rows):
for _ in range(rows):
Copy link
Author

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:

Comment on lines -10 to +14
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}
Copy link
Author

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:

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)
Copy link
Author

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:

headers = next(rows)
for row in rows:
records.append(cls.from_row(row))
records.extend(cls.from_row(row) for row in rows)
Copy link
Author

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:

print('<tr>', end=' ')
for h in headers:
print('<th>%s</th>' % h, end=' ')
print(f'<th>{h}</th>', end=' ')
Copy link
Author

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:

print('<tr>', end=' ')
for d in rowdata:
print('<td>%s</td>' % d, end=' ')
print(f'<td>{d}</td>', end=' ')
Copy link
Author

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:

formatter_cls = HTMLTableFormatter
else:
raise RuntimeError('Unknown format %s' % name)
raise RuntimeError(f'Unknown format {name}')
Copy link
Author

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:


def typedproperty(name, expected_type):
private_name = '_' + name
private_name = f'_{name}'
Copy link
Author

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:

super().__setattr__(name, value)
else:
raise AttributeError('No attribute %s' % name)
raise AttributeError(f'No attribute {name}')
Copy link
Author

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:

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)})"
Copy link
Author

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:

super().__setattr__(name, value)
else:
raise AttributeError('No attribute %s' % name)
raise AttributeError(f'No attribute {name}')
Copy link
Author

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:

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)})"
Copy link
Author

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:

super().__setattr__(name, value)
else:
raise AttributeError('No attribute %s' % name)
raise AttributeError(f'No attribute {name}')
Copy link
Author

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:

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)})"
Copy link
Author

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:

class StructureMeta(type):
@classmethod
def __prepare__(meta, clsname, bases):
def __prepare__(cls, clsname, bases):
Copy link
Author

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:

Comment on lines -12 to +14
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)
Copy link
Author

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:

super().__setattr__(name, value)
else:
raise AttributeError('No attribute %s' % name)
raise AttributeError(f'No attribute {name}')
Copy link
Author

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:

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)})"
Copy link
Author

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:

Comment on lines -69 to +80
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()


Copy link
Author

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:

def typed_structure(clsname, **validators):
cls = type(clsname, (Structure,), validators)
return cls
return type(clsname, (Structure,), validators)
Copy link
Author

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:

print('<tr>', end=' ')
for h in headers:
print('<th>%s</th>' % h, end=' ')
print(f'<th>{h}</th>', end=' ')
Copy link
Author

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:

print('<tr>', end=' ')
for d in rowdata:
print('<td>%s</td>' % d, end=' ')
print(f'<td>{d}</td>', end=' ')
Copy link
Author

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:

formatter_cls = HTMLTableFormatter
else:
raise RuntimeError('Unknown format %s' % name)
raise RuntimeError(f'Unknown format {name}')
Copy link
Author

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:

class StructureMeta(type):
@classmethod
def __prepare__(meta, clsname, bases):
def __prepare__(cls, clsname, bases):
Copy link
Author

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:

def typed_structure(clsname, **validators):
cls = type(clsname, (Structure,), validators)
return cls
return type(clsname, (Structure,), validators)
Copy link
Author

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:

print('<tr>', end=' ')
for h in headers:
print('<th>%s</th>' % h, end=' ')
print(f'<th>{h}</th>', end=' ')
Copy link
Author

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:

print('<tr>', end=' ')
for d in rowdata:
print('<td>%s</td>' % d, end=' ')
print(f'<td>{d}</td>', end=' ')
Copy link
Author

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:

formatter_cls = HTMLTableFormatter
else:
raise RuntimeError('Unknown format %s' % name)
raise RuntimeError(f'Unknown format {name}')
Copy link
Author

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:

class StructureMeta(type):
@classmethod
def __prepare__(meta, clsname, bases):
def __prepare__(cls, clsname, bases):
Copy link
Author

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:

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