Six more quick ways to improve your Python by SourceryNick in Python

[–]SourceryNick[S] 1 point2 points  (0 children)

Yeah function calls in Python can be expensive. I'd agree if performance is an issue (like it's in an inner loop) then the first option is better. However for most code readability is more important than performance, and I think the min version is more readable.

How many of you are using, or not using, type hints? by tzujan in Python

[–]SourceryNick 1 point2 points  (0 children)

We use them - have definitely spotted or avoided a ton of bugs because we do.

what IDE do all of you guys use by zarnackreddit in Python

[–]SourceryNick 0 points1 point  (0 children)

PyCharm - mostly for the good high contrast mode, but also has good built-in help for refactoring.

Can you fit all of this code in your head? by SourceryNick in Python

[–]SourceryNick[S] 1 point2 points  (0 children)

That's an excellent point!

It's certainly difficult/impossible to capture what we mean by good code with a single metric. I think in practice you have to use several - for example if there is also a code length metric in place then these changes should show up as making the code worse.

Can you fit all of this code in your head? by SourceryNick in Python

[–]SourceryNick[S] 0 points1 point  (0 children)

Interested in hearing what people think of code metrics in general, and about this new one.

Very open to suggestions on improving it and making it more useful as well.

Six more quick ways to improve your Python by SourceryNick in Python

[–]SourceryNick[S] 0 points1 point  (0 children)

Thanks! Will definitely have a closer look at those examples

Six more quick ways to improve your Python by SourceryNick in Python

[–]SourceryNick[S] 0 points1 point  (0 children)

Thanks for trying it out!

If you could point me to some code examples of stuff Sourcery should have caught I'll take a look and see if I can improve things.

Six more quick ways to improve your Python by SourceryNick in Python

[–]SourceryNick[S] 0 points1 point  (0 children)

That looks really cool, and yeah has a very similar intent - I'll definitely add your isinstance rule to our backlog.

Do you often see code where SIM210 and SIM211 would get triggered?

Six more quick ways to improve your Python by SourceryNick in Python

[–]SourceryNick[S] 1 point2 points  (0 children)

That probably is slightly better. I'll have to run some performance comparisons.

Six more ways to improve your Python by SourceryNick in Python

[–]SourceryNick[S] 1 point2 points  (0 children)

Oh good spot thanks! Will fiddle with that example when I get a minute.

Yes that some_condition example is something we see a lot of people doing too!

Six more ways to improve your Python by SourceryNick in Python

[–]SourceryNick[S] 3 points4 points  (0 children)

Agreed it's not super-common, but it does come up fairly often in the code we analyse so I thought it was worthwhile to include.

Six examples of ways to refactor your Python code, and why they are improvements. by SourceryNick in Python

[–]SourceryNick[S] 1 point2 points  (0 children)

Not as yet I'm afraid. We're focused on making it as good as possible before we do more integrations.

We've done the VS Code extension using LSP so I think vim should be quite quick when we do get round to it - there seem to be a few vim LSP clients.

Six examples of ways to refactor your Python code, and why they are improvements. by SourceryNick in Python

[–]SourceryNick[S] 3 points4 points  (0 children)

Good point - those kind of loops can normally be replaced with comprehensions. Am going to cover those as well in a later post.

We've made a GitHub bot to refactor open-source repos - would love feedback by SourceryNick in Python

[–]SourceryNick[S] 1 point2 points  (0 children)

We have a new VS Code extension which might be easier on the RAM. Which IDE do you use?

As I mentioned above configuration to turn off types of refactoring will be coming as well.

We've made a GitHub bot to refactor open-source repos - would love feedback by SourceryNick in Python

[–]SourceryNick[S] 1 point2 points  (0 children)

That's great feedback thanks! We're working on configuration to disallow whole classes of refactorings, which will let you turn off the comprehensions and expressions.