sourcery-ai / sourcery Goto Github PK
View Code? Open in Web Editor NEWInstant AI code reviews
Home Page: https://sourcery.ai
License: MIT License
Instant AI code reviews
Home Page: https://sourcery.ai
License: MIT License
The Sorcery service is unable to start / look for the latest version of the offline sorcery engine when PyCharm is set to use a proxy.
More specifically, this happens when I run inside a corporate environment, where all internet traffic
is routed through a proxy.
When I try to run sorcery on a different network, it works as expected.
Note that PyCharm is set to use the appropriate proxy, but sorcery seem to be trying to connect to the internet directly.
Plugin version: 0.2.7
Sourcery version: 0.5.11
Pycharm 2019.3.2
macOS 10.14.6
Hello, i have tried this out and it looks pretty nice, but this obviously is wrong:
del fields["full_name"]
- elif "full_name" in fields and ("first_name" in fields or "last_name" in fields):
+ elif "full_name" in fields:
raise Exception(
Sourcery complains about this code with a "Replace unused for index with underscore" at the location marked with "FP here"
def translate(data, keys):
r = ['abcd']
nos = 100
for i in range(nos): # <- FP here
r.append([data[k][i] for k in keys])
return r
It converts the code to
def translate(data, keys):
r = ['abcd']
nos = 100
for _ in range(nos):
r.append([data[k][i] for k in keys])
return r
Which will lead to an exception:
NameError: name 'i' is not defined
The code is contrived, reducing it further will lead to other suggestions (like use list-comprehension). Nevertheless, Sourcery should not suggest this particular change, because it breaks the code.
Sourcery plugin for PyCharm.
Plan: Sourcery Open Source. Plugin version: 0.3.7. Sourcery Version: 0.7.0.
PyCharm 2020.1.1 (Professional Edition)
Build #PY-201.7223.92, built on April 30, 2020
Runtime version: 11.0.6+8-b765.40 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 1088M
Cores: 8
Non-Bundled Plugins: mobi.hsz.idea.gitignore, mobi.hsz.idea.latex, nl.rubensten.texifyidea, sourcery.pycharm-plugin, org.sonarlint.idea, org.toml.lang, org.rust.lang
Windows 10, build 19635.1
Right now if you have @sourcery-ai-bot installed for your GitHub repository it opens a separate PR. In this new PR it simply adds all refactorings without comments.
If you let it refactor the master
branch it opens a PR with a review comment for every change its made.
Is it possible to use the second approach also for PRs? GitHub review have the option to "insert suggestions" (see 6 in https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/commenting-on-a-pull-request#adding-line-comments-to-a-pull-request). Such a suggestion can be accepted and automatically committed to the current PR with a single click.
Incorporating this would mean that all changes including a possible discussion if a change is accepted would stay in the same PR. Furthermore, with it you have the option the accept / refuse changes without pulling the PR to your local repository and edit it manually.
Open project, clicked on run in Sourcery plugin and saw an issue. Clicked on the issue, convert loop to list comprehension and I could see that there was a suggestion but perhaps the text was to long as I could not see the correction or suggested test (assuming that what is it). Please see screenshot.
Pycharm v2019.2.1 Pro
Linux
There are some large files in my project. Result from the above, when sourcery scans these file, it takes lot of time and lot of cpu usage. To figure this problem, I prefer to skip some files that they don't need to be scanned.
Plan: Sourcery Pro.
Plugin version: 0.3.0
Sourcery Version: 0.5.11
PyCharm 2019.3.3 (Professional Edition)
Build #PY-193.6494.30, built on February 6, 2020
OSX 10.15.3
After adding an third party package django_q
to INSTALLED_APPS
in my Django project I got this:
java.lang.NullPointerException
at ai.sourcery.intellij.ui.SourceryWindowPanel.renameFile(SourceryWindowPanel.java:403)
at ai.sourcery.intellij.SourceryPlugin$1.lambda$renameFile$0(SourceryPlugin.java:103)
at com.intellij.openapi.application.TransactionGuardImpl$2.run(TransactionGuardImpl.java:312)
at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.doRun(LaterInvocator.java:433)
at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.runNextEvent(LaterInvocator.java:416)
at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:399)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:776)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:746)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:873)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:822)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:461)
at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:704)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:460)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Pycharm v2019.2
Windows
The tool leaves false CI failures in your commit record, which is bad for projects that pride themselves on no failures (like mine)
e.g. https://github.com/rec/safer/commits/master - only one red X in over 100 commits and it's from you.
I signed up with six projects and now I have five failures on my otherwise clean record.
Often available in Sourcery settings
Github
n/a
Open a file and convert it to split view. Now open a different file.
Sourcery will incorrectly switch the view back to the first one.
By clicking quickly through different files Sourcery will sometimes switch quickly back and forth between them.
0.3.3
Pycharm v2019.3
Linux
My repositories all use Black for code formatting, and it has become somewhat of a standard across Python projects.
Issue: The Sourcery bot makes code formatting suggestions that don't pass the black pre-commit hooks in the linting stage of CI because the suggestions use single quotes for strings and other formatting problems. This requires then fetching the proposed changes, running the pre-commit hooks, and pushing the changes back to the branch.
Possible solutions:
Sourcery wants to hoist comments out of loops
0.3.0
Often available in Sourcery settings
Pycharm v2019.3
Windows 10
I have noticed that sourcery frequently wants to hoist comments out of loops. I get entire reformat suggestions that are based on comments being hoisted up.
This doesn't seem like something you actually want.
Can't use sourcery because it fails to find the binary during configuration
This may well be an issue with my work network though my other plugins do not have this issue. Is it possible to download the plugin and install it manually?
All versions
Pycharm v?
2019.3
Windows 10
This is either a bug report or an inappropriate complaint. Unfortunately, I don't have enough information to determine which is the case.
I wanted to give sourcery
a try so I starred it here on GitHub. Directly afterwards @sourcery-ai-bot starred and forked the repository I wanted to be checked. I expected it to send a PR with all possible refactorings, but up until now (16h later) nothing happened. Could you check if everything is working as you expected it to do?
If that is the case and I'm just too impatient, could you tell me what the "normal" timeline is?
while run_mallocfail(exe, timeout):
pass
I could rewrite this to say
while True:
if run_mallocfail(exe, timeout):
pass
but really sourcery should only do safe refactorings.
See TokTok/toktok-stack@fc31fd8#diff-9943d64762e22ec9d53b7aec416b9c29L82
I was using Sourcery in alpha, but then didn't use it for a while. I recently updated the plugin to 0.1.2 (and updated my token) and found that the Sourcery service no longer starts, giving the following error:
2:47 PM Failed to launch Sourcery service: login() missing 2 required positional arguments: 'plugin_version' and 'protocol_version'
0.1.2
Pycharm v2018.1.1
Windows 10
I installed Sourcery as a GitHub Integration to an organization with open source repositories. I click on the refactor master button, and your website says: "Successful started refactoring job for master." I have told it to refactor multiple times over the last 24 hours, and there hasn't been a pull request made to the repo.
One of my co-developers did submit a PR, and sourcery-ai created a new PR with correction to it, so that part of the integration is working.
import asyncio
class MyAwaitable:
def __await__(self):
print("__await__")
yield
async def main():
x = MyAwaitable()
for _ in range(3):
await x
asyncio.run(main())
This code prints "await" three times. Sourcery suggests to hoist statements out of for/while loops for await x
:
async def main():
x = MyAwaitable()
await x
This code prints "await" only once.
Side note: Sourcery does not suggest to hoist the statement if the operand of await is a call:
import asyncio
class MyAwaitable:
def __await__(self):
print("__await__")
yield
def __call__(self):
return self
async def main():
x = MyAwaitable()
for _ in range(3):
await x()
asyncio.run(main())
This code prints "await" three times. asyncio (the module) seems to return awaitables from calls like await asyncio.sleep(1)
most of the time if not always.
Plan: Sourcery open Source. Plugin version: 0.3.7. Sourcery Version: 0.7.0.
Pycharm v2020.1.1 (Professional Edition)
Arch Linux
Description of some issues doesn't seem right
0.3.0
Often available in Sourcery settings
Pycharm v2019.3
Windows 10
A typical example would be:
def x():
return
print('Unreachable')
For me, the message says, "remove redundant code" and it will delete everything under the return. This isn't redundant code, it's just unreachable and probably represents a mistake. Deleting it as redundant is certainly a mistake.
I think the vocabulary should change to unreachable but I am unsure what the correct refactor (if any) should be.
from common.errors import ValidationError
def set_status(status: str) -> str:
if status:
if status.upper().strip() == "ON":
result = "starting"
elif status.upper().strip() == "OFF":
result = ""
else:
# raise Exception() does not trigger any refactor
raise ValidationError(title="Invalid status", description="Status can be on or off")
else:
raise ValidationError(title="Invalid status", description="Status can be on or off")
return result
Pycharm 2019.1.3
Linux
Is there a way to tell Sourcery (or PyCharm) to ignore certain refactoring suggestions?
It's not that the suggestions are wrong, but sometimes I prefer the way the code reads without the refactoring. I can't seem to find a way to tell Sourcery to stop highlighting this part of the code, so I'm just turning off Sourcery for now.
Pycharm v2018.1.4 Community Edition
Linux
Original code:
# -*- coding: utf-8 -*-
"""Root URL routing of the radio downloader project."""
from django.conf import settings
from django.conf.urls import static
from django.contrib import admin
from django.urls import include, path
from django.utils.translation import gettext_lazy as _
from django.views.generic import TemplateView
urlpatterns = [
path(
route='admin/',
view=admin.site.urls
),
path(
route="",
view=TemplateView.as_view(template_name="home.html"),
name="home"
)
]
if settings.DEBUG is True:
urlpatterns += static.static(
settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT
)
will get refactored to
# -*- coding: utf-8 -*-
"""Root URL routing of the radio downloader project."""
from django.conf import settings
from django.conf.urls import static
from django.contrib import admin
from django.urls import include, path
from django.utils.translation import gettext_lazy as _
from django.views.generic import TemplateView
if settings.DEBUG is True:
urlpatterns = [
path(
route='admin/',
view=admin.site.urls
),
path(
route="",
view=TemplateView.as_view(template_name="home.html"),
name="home"
)
]
urlpatterns += static.static(
settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT
)
Hint Move assignments closer to their usage
This does not make sense at all.
Pycharm v2019.2
Windows
while editing in Pycharm, I get the error: Unable to connect to Sourcery executable: expected str, bytes or os.PathLike object, not NoneType
Plan: Sourcery Pro. Plugin version: 0.3.2. Sourcery Version: 0.6.4
Pycharm 2019.2.5 (Professional Edition) Build #PY-192.7142.56, November 19, 2019
Windows 10, running pycharm in WSL 2 on Ubuntu 18.04 LTS
Consider the following snippet:
if foo:
bar = 1e-4
else:
bar = 1e15
This gets refactored to
bar = 0.0001 if foo else 1000000000000000.0
which is correct but quite cumbersome. If you decrease or increase the exponent any further, the scientific formatting is retained:
if foo:
bar = 1e-5
else:
bar = 1e16
bar = 1e-05 if foo else 1e+16
Sourcery Starbot (see https://github.com/pmeier/pystiche/pull/270/files#r433867794)
Less than sign missing from diff window in suggested refactoring.
Pycharm
Not known.
Before:
def sth(somedict):
if not somedict.get("somekey"):
return False
return True
After:
def sth(somedict):
return somedict.get("somekey")
As you can see a check for the existence of a key which is meant to return a boolean is refactored to returning the actual value under the key which could easily be False
.
Pycharm v2019.2.1
OSX 10.14.6
I have installed Sourcery plugin, and when it starts to download I got an error:
Failed to download Sourcery: Downloaded version returns error
I have tried turning off pycharm, and restarted computer, uninstalled Sourcery plugin, and installed it again. End result is always the same.
Pycharm 2019.3
Linux, 5.0.21-1
Add a comment here to register interest in Sourcery support for other IDEs.
Or read our docs for how to write an editor plugin using our LSP server
Using the Github Star Bot to create a pull request, there is a strange artifact where strings are duplicated upon condensing a series of list.append()
calls into a single return [list, content]
.
See (Actual output): CodeBizarre/discord-bot@528fcfb#diff-5bc02cefb3ea9e27f1a6776eabd1935dL91
Fixed (Expected output): CodeBizarre/discord-bot@b9c5db1
sourcery-ai-bot via github star, I don't see a version listed anywhere
I've omitted the n/a sections of the default issue since I did not use sourcery locally, only through the github star bot.
Sourcery Plugin fails to launch in PyCharm IDE. After upgrading to PyCharm 2020.1 from 2019.3 Sourcery fails to load.
Error message in Event Log:
6:20 PM Failed to launch Sourcery service: RecordCollection contained more than one row. Expects only one row when using RecordCollection.one
I have tried completely uninstalling and reinstalling PyCharm 2020.1; uninstalling and installing 2019.3 : on both I only installed the Sourcery Plugin. In all cases I get the exact same error.
Any idea of where this RecordCollection.one is stored and how I can fix this?
Sourcery 0.3.7
PyCharm 2020.1.1 (Professional Edition)
Build #PY-201.7223.92, built on April 29, 2020
Licensed to -snip-
Subscription is active until February -snip-
Runtime version: 11.0.6+8-b765.40 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 1998M
Cores: 4
Non-Bundled Plugins: sourcery.pycharm-plugin
Windows 10 Version 1909 (OS Build 18363.836)
def set_status(status: str) -> str:
if status:
if status.upper().strip() == "ON":
result = "starting"
elif status.upper().strip() == "OFF":
result = ""
else:
raise ValidationError(title="Invalid status", description="Status can be on or off")
else:
raise ValidationError(title="Invalid status", description="Status can be on or off")
return result
is refactored into:
def set_status(status: str) -> str:
if status and status.upper().strip() == "ON":
result = "starting"
elif status and status.upper().strip() != "ON" and status.upper().strip() == "OFF":
result = ""
else:
raise ValidationError(title="Invalid status", description="Status can be on or off")
return result
Even if everything is syntactically and semantically correct, the following condition is a bit strange:
status and status.upper().strip() != "ON" and status.upper().strip() == "OFF"
Pycharm 2019.1.3
Linux
import numpy
x = np.array(list([1, 2, 3]))
x = x / x.sum()
# becomes:
x /= x.sum()
# the /= magic method is not supported in numpy
Pycharm
Not known - raised by Andrew Louw
The simplify generator refactoring changes the type of the returned object from a generator to a different type. If the code relies on it being a generator this will change program behaviour.
e.g:
a = {'a': 1, 'b': 2}
next(b for b in a.keys())
is transformed to the incorrect:
a = {'a': 1, 'b': 2}
next(a.keys())
Often available in Sourcery settings
Pycharm
All
VSCODE
Linux Ubuntu 20,4
Refactoring doesn't respect the line-widths.
Here's an example. Before:
val = []
for sub_attr_value in attr_value:
val.append(sub_attr_value.to_dict(
deep=deep,
serialisable=serialisable
))
After:
val = [sub_attr_value.to_dict(deep=deep, serialisable=serialisable) for sub_attr_value in attr_value]
This isn't a major deal but will then require re-refactoring or running black
to bring the code back in shape.
Pycharm v2019.2.1
OSX 10.14.6
Sourcery incorrectly refactoring functions with nested functions defined.
e.g.
def func():
def inner_func():
for report in item.get(report_type, []):
result.append(something)
result = []
for area_code, item in area_list.items():
inner_func()
return result
0.6.5
Pycharm
Linux
Repo is here:
https://github.com/xnuinside/laziest
Github bot
Refactoring a snippet seems to have lead to the Union
annotation being wrapped into a tuple for no good reason.
Before:
from typing import Union
def _et(element) -> Union[str, None]:
"""Extracts the element text (ET)."""
text = None
if element is not None:
text = element.text
if not text:
text = None
else:
text = text.strip()
return text
After:
from typing import Union
def _et(element) -> Union[(str, None)]:
"""Extracts the element text (ET)."""
text = None
if element is not None:
text = element.text
text = None if not text else text.strip()
return text
Note how Union[str, None]
became Union[(str, None)]
Pycharm v2019.2.1
OSX 10.14.6
Pycharm 2019.1.3
Linux
This
if x in [a, b]:
return y
elif x == c:
return y
else:
return z
becomes:
if x in [a, b] or x == c:
return y
else:
return z
this would be better:
if x in [a, b, c]:
return y
else:
return z
If you follow the link to Sourcery Pro, it'll open (Firefox for me) with a blank page:
https://sourcery.ai/subscribe/?product=pro
This exception is in the dev console:
Error: "usePlans must be used within a PlansProvider"
N/A -- this is a web error.
Sourcery only works for Python 3
Sourcery can delete comments and whitespace inappropriately.
Sourcery does not currently handle async functions and the await keyword correctly.
Sourcery is not yet enabled for IntelliJ batch inspections (scanning every file in a project or directory at once)
Sourcery does not correctly handle properties that depend on other variables.
installed and uninstalled
installation table - enabled column
This horrible way of iterating is not picked up:
x0 = ['a', 'b']
x1 = {'a': 1, 'b': 2, 'c': 3}
for i in x1.copy(): # can't iterate over a variable that changes size
if i not in x0:
del x1[i]
when the much cleaner version is available.
x0 = ['a', 'b']
x1 = {'a': 1, 'b': 2, 'c': 3}
x1 = {k: v for k, v in x1.copy().items() if k in x0}
Pycharm 2019.1.3?
Windows 10
Delete a function name, leaving the rest of the function intact.
Sourcery will throw the following error and then reconnect:
expected str, bytes or os.PathLike object, not NoneType
0.6.4
Pycharm 2019
Linux
open a flask python project, after some indexing of the ide, the event log keep popping this message:
11:36 Unable to connect to Sourcery executable: org.eclipse.lsp4j.jsonrpc.JsonRpcException: java.io.IOException: Stream closed
11:37 Unable to connect to Sourcery executable
11:38 Unable to connect to Sourcery executable
...
The first message tell a jsonrpc exception, then others take place on every minute.
0.3.5
Idea 2020.1.1 with python plugin
OSX 10.15.4
Sourcery can duplicate lines incorrectly - see this cut down example:
def appendPagesFromReader(self):
# Copy pages from reader to writer
for rpagenum in range(reader_num_pages):
self.addPage(reader_page)
writer_page = self.getPage(writer_num_pages + rpagenum)
# Trigger callback, pass writer page as parameter
if callable(after_page_append): after_page_append(writer_page)
0.6.8
GitHub bot
N/A
There is a background process running saying Sourcery update check complete, and constantly trowing out error notifications saying the following. The correct API token is entered in the settings. The certifi
folder is not present.
Unable to connect to Sourcery executable: Could not find a suitable TLS CA certificate bundle, invalid path: C:\Users\jakub\AppData\Roaming\sourcery\bin\certifi\cacert.pem
Pycharm v2019.2.4
Windows 10 1903
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.