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 develop branch, then run:

git fetch https://github.com/sourcery-ai-bot/pymaid develop
git merge --ff-only FETCH_HEAD
git reset HEAD^

Comment on lines -55 to +60
for filename in filenames:
if filename.endswith('.proto'):
protos.append(os.path.join(root, filename))
protos.extend(
os.path.join(root, filename)
for filename in filenames
if filename.endswith('.proto')
)

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_protos refactored with the following changes:

def connection_made(self, transport):
sock = transport.get_extra_info('socket')
args.debug('Connection to {}'.format(sock))
args.debug(f'Connection to {sock}')
Copy link
Author

Choose a reason for hiding this comment

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

Function EchoProtocol.connection_made refactored with the following changes:

req = b'a' * args.msize
receive_event = protocol.receive_event = asyncio.Event()
for x in range(count):
for _ in range(count):
Copy link
Author

Choose a reason for hiding this comment

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

Function wrapper refactored with the following changes:

Comment on lines -55 to +57
tasks = []
for x in range(args.concurrency):
tasks.append(asyncio.create_task(
tasks = [asyncio.create_task(
wrapper(loop, args.address, args.request)
))

) for _ in range(args.concurrency)]
Copy link
Author

Choose a reason for hiding this comment

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

Function main refactored with the following changes:

def connection_made(self, transport):
sock = transport.get_extra_info('socket')
args.debug('Connection from {}'.format(sock))
args.debug(f'Connection from {sock}')
Copy link
Author

Choose a reason for hiding this comment

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

Function EchoProtocol.connection_made refactored with the following changes:

Comment on lines -16 to +25
tasks = []
address = args.address
request = args.request
for x in range(args.concurrency):
tasks.append(
pymaid.create_task(
tasks = [pymaid.create_task(
worker(
address,
service,
request,
transport_class=WebSocket | Connection,
)
)
)

) for _ in range(args.concurrency)]
Copy link
Author

Choose a reason for hiding this comment

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

Function main refactored with the following changes:

Comment on lines -92 to +97
for filename in filenames:
if filename.endswith('_pb2.py'):
modules.append(os.path.join(root, filename))
modules.extend(
os.path.join(root, filename)
for filename in filenames
if filename.endswith('_pb2.py')
)

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_modules refactored with the following changes:

Comment on lines -119 to +122
fields.extend(extra_message(field.message_type, indent + ' '))
fields.extend(extra_message(field.message_type, f'{indent} '))
Copy link
Author

Choose a reason for hiding this comment

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

Function extra_message refactored with the following changes:

Comment on lines -133 to +141
req = star_indent + 'req: ' + method.input_type.name + star_indent
req = f'{star_indent}req: {method.input_type.name}{star_indent}'
req += star_indent.join(extra_message(method.input_type))
resp = star_indent + 'resp: ' + method.output_type.name + star_indent
resp = f'{star_indent}resp: {method.output_type.name}{star_indent}'
resp += star_indent.join(extra_message(method.output_type))
input_type = prefix + '.' + method.input_type.full_name
output_type = prefix + '.' + method.output_type.full_name
input_type = f'{prefix}.{method.input_type.full_name}'
output_type = f'{prefix}.{method.output_type.full_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 generate_jsimpl refactored with the following changes:

Comment on lines -178 to +181
with open(file_path + '_broadcast.js', 'w') as fp:
with open(f'{file_path}_broadcast.js', 'w') as fp:
Copy link
Author

Choose a reason for hiding this comment

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

Function generate refactored with the following changes:

Comment on lines -59 to +64
for filename in filenames:
if filename.endswith('_pb2.py'):
modules.append(os.path.join(root, filename))
modules.extend(
os.path.join(root, filename)
for filename in filenames
if filename.endswith('_pb2.py')
)

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_modules refactored with the following changes:

Comment on lines -86 to +90
input_type = prefix + '.' + method.input_type.full_name
output_type = prefix + '.' + method.output_type.full_name
input_type = f'{prefix}.{method.input_type.full_name}'
output_type = f'{prefix}.{method.output_type.full_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 generate_js_rpc refactored with the following changes:

Comment on lines -115 to +118
with open(file_path + '_rpc.js', 'w') as fp:
with open(f'{file_path}_rpc.js', 'w') as fp:
Copy link
Author

Choose a reason for hiding this comment

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

Function generate refactored with the following changes:

if self.subparsers:
subcmd = self.get_subcmd(args)
if subcmd:
if subcmd := self.get_subcmd(args):
Copy link
Author

Choose a reason for hiding this comment

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

Function ArgumentParser.on_parse_callback refactored with the following changes:

nid = item['notificationId']
data = get_data(ns, self.subscriptions[ns]['format'])
if data:
if data := get_data(ns, self.subscriptions[ns]['format']):
Copy link
Author

Choose a reason for hiding this comment

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

Function ApolloBackend.run refactored with the following changes:

fragment = parsed.fragment

if 'unix' == scheme:
if scheme == 'unix':
Copy link
Author

Choose a reason for hiding this comment

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

Function parse_uri refactored with the following changes:

Comment on lines -256 to +259
if ('websocket' != headers.get('Upgrade', '').lower()
or 'upgrade' != headers.get('Connection', '').lower()):
if (
headers.get('Upgrade', '').lower() != 'websocket'
or headers.get('Connection', '').lower() != 'upgrade'
):
Copy link
Author

Choose a reason for hiding this comment

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

Function WSProtocol.build_response refactored with the following changes:

Comment on lines -277 to +282
if ('websocket' != headers.get('Upgrade', '').lower()
or 'upgrade' != headers.get('Connection', '').lower()):
if (
headers.get('Upgrade', '').lower() != 'websocket'
or headers.get('Connection', '').lower() != 'upgrade'
):
Copy link
Author

Choose a reason for hiding this comment

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

Function WSProtocol.validate_upgrade refactored with the following changes:

Comment on lines -338 to +374
if self.opcode == self.OPCODE_CLOSE:
payload = self.payload
length = self.length
if not length:
self.close_reason = CloseReason.NO_STATUS_RCVD
elif length == 1:
raise ProtocolError(f'Invalid close frame: {self} {payload}')
if self.opcode != self.OPCODE_CLOSE:
return
payload = self.payload
length = self.length
if not length:
self.close_reason = CloseReason.NO_STATUS_RCVD
elif length == 1:
raise ProtocolError(f'Invalid close frame: {self} {payload}')
else:
code = unpack_H(payload[:2])[0]
if code < MIN_CLOSE_REASON or code > MAX_CLOSE_REASON:
raise ProtocolError('invalid close code range')
try:
code = CloseReason(code)
except ValueError:
pass
if code in LOCAL_ONLY_CLOSE_REASONS:
raise ProtocolError('remote CLOSE with local-only reason')
if (not isinstance(code, CloseReason)
and code <= MAX_PROTOCOL_CLOSE_REASON):
raise ProtocolError('CLOSE with unknown reserved code')
try:
reason = payload[2:].decode('utf-8')
except UnicodeDecodeError:
raise ProtocolError(
'close reason is not valid UTF-8',
CloseReason.INVALID_FRAME_PAYLOAD_DATA,
)
if isinstance(code, CloseReason):
code.reason = reason
else:
code = unpack_H(payload[:2])[0]
if code < MIN_CLOSE_REASON or code > MAX_CLOSE_REASON:
raise ProtocolError('invalid close code range')
try:
code = CloseReason(code)
except ValueError:
pass
if code in LOCAL_ONLY_CLOSE_REASONS:
raise ProtocolError('remote CLOSE with local-only reason')
if (not isinstance(code, CloseReason)
and code <= MAX_PROTOCOL_CLOSE_REASON):
raise ProtocolError('CLOSE with unknown reserved code')
try:
reason = payload[2:].decode('utf-8')
except UnicodeDecodeError:
raise ProtocolError(
'close reason is not valid UTF-8',
CloseReason.INVALID_FRAME_PAYLOAD_DATA,
)
if isinstance(code, CloseReason):
code.reason = reason
else:
code = (code, reason)
self.close_reason = code
code = (code, reason)
self.close_reason = code
Copy link
Author

Choose a reason for hiding this comment

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

Function Frame.prepare refactored with the following changes:

self.outbound_transmission_id = 1
else:
self.outbound_transmission_id = 2
self.outbound_transmission_id = 1 if initiative else 2
Copy link
Author

Choose a reason for hiding this comment

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

Function ContextManager.__init__ refactored with the following changes:

routes[method.full_name] = method
# js/lua pb lib will format as '.service.method'
routes['.' + method.full_name] = method
routes[f'.{method.full_name}'] = method
Copy link
Author

Choose a reason for hiding this comment

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

Function Router.include_service refactored with the following changes:

Comment on lines -28 to +36
elif not mdp.client_streaming and mdp.server_streaming:
elif not mdp.client_streaming:
method_class = UnaryStreamMethod
elif mdp.client_streaming and not mdp.server_streaming:
elif not mdp.server_streaming:
method_class = StreamUnaryMethod
elif mdp.client_streaming and mdp.server_streaming:
method_class = StreamStreamMethod
else:
assert False, 'should be one of above'

method_class = StreamStreamMethod
request_class = service.GetRequestClass(method)
response_class = service.GetResponseClass(method)
method_ins = method_class(
yield method_class(
Copy link
Author

Choose a reason for hiding this comment

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

Function PBRouter.get_service_methods refactored with the following changes:

Comment on lines -120 to +124
elif not mdp.client_streaming and mdp.server_streaming:
elif not mdp.client_streaming:
method_class = UnaryStreamMethodStub
elif mdp.client_streaming and not mdp.server_streaming:
elif not mdp.server_streaming:
method_class = StreamUnaryMethodStub
elif mdp.client_streaming and mdp.server_streaming:
method_class = StreamStreamMethodStub
else:
assert False, 'should be one of above'

method_class = StreamStreamMethodStub
request_class = stub.GetRequestClass(method)
response_class = stub.GetResponseClass(method)
method_stub = method_class(
yield method_class(
Copy link
Author

Choose a reason for hiding this comment

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

Function PBRouterStub.get_router_stubs refactored with the following changes:

raise ValueError('Not a cached Python file extension', ext)
# Should we look for .pyw files?
return basename + '.py'
return f'{basename}.py'
Copy link
Author

Choose a reason for hiding this comment

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

Function source_from_cache refactored with the following changes:

PY3 = True
else:
PY3 = False
PY3 = sys.version_info[0] >= 3
Copy link
Author

Choose a reason for hiding this comment

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

Lines 48-51 refactored with the following changes:

Comment on lines -33 to +37
if not isinstance(other, HashNode):
return NotImplemented
return self.hashed_key == other.hashed_key
return (
self.hashed_key == other.hashed_key
if isinstance(other, HashNode)
else NotImplemented
)
Copy link
Author

Choose a reason for hiding this comment

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

Function HashNode.__eq__ refactored with the following changes:

Comment on lines -194 to +197
offset = hash_func('cat' + key) % entry_count
skip = (hash_func('lee' + key) % (entry_count - 1)) + 1
offset = hash_func(f'cat{key}') % entry_count
skip = hash_func(f'lee{key}') % (entry_count - 1) + 1
Copy link
Author

Choose a reason for hiding this comment

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

Function MaglevHash.rehash refactored with the following changes:

Comment on lines -221 to +223
key = self.hash_func('cat' + key)
key = self.hash_func(f'cat{key}')
Copy link
Author

Choose a reason for hiding this comment

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

Function MaglevHash.get_node refactored with the following changes:

deadline = get_running_loop().time() + delay # type: Optional[float]
else:
deadline = None
deadline = get_running_loop().time() + delay if delay is not None else 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 timeout refactored with the following changes:

This removes the following comments ( why? ):

# type: Optional[float]

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