Skip to content
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

General code cleanup #507

Merged
merged 6 commits into from
Jan 3, 2020
Merged

General code cleanup #507

merged 6 commits into from
Jan 3, 2020

Conversation

eforgacs
Copy link
Contributor

Removing unnecessary parentheses, test for membership should be "not in", typo fixes, indentation/spacing, changing from use of deprecated functions to non-deprecated functions, capitalization, fixing syntax of Bash scripts, line length, added "await" to coroutine that is not awaited.

Removing unnecessary parentheses, test for membership should be "not in", typo fixes, indentation/spacing, changing from use of deprecated functions to non-deprecated functions, capitalization, fixing syntax of Bash scripts, line length, added "await" to coroutine that is not awaited.
@@ -7,7 +7,7 @@

def test_with_logger():
@with_logger
class testclass():
class testclass:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can be camel case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Just changed it.

Removing unnecessary parentheses, test for membership should be "not in", typo fixes, indentation/spacing, changing from use of deprecated functions to non-deprecated functions, capitalization, fixing syntax of Bash scripts, line length, added "await" to coroutine that is not awaited.

Changes in this commit:
- Making TestClass use CamelCase (tests/unit_tests/test_decorators.py)
Copy link
Collaborator

@Askaholic Askaholic left a comment

Choose a reason for hiding this comment

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

If you wanted to you could run a few of these files through black and see if it produces anything sane.

@@ -1,2 +1,2 @@
#! /bin/bash
docker exec -i faf-db mysql faf < test-data.sql && scripts/run_tests_with_coverage.sh $@
docker exec -i faf-db mysql faf < test-data.sql && scripts/run_tests_with_coverage.sh "$@"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you sure this will still work? The point is to forward all command line arguments to pytest so that for example you can do pipenv run tests tests/integration_tests -s --cli-log-level 5. I would think that adding quotes would mash all of your arguments into a single string, which presumably doesn't get parsed correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's the warning from ShellCheck that I get when I leave it in its current state:

"Double quote array expansions to avoid re-splitting elements."

Rationale:
Double quotes around $@ (and similarly, ${array[@]}) prevents globbing and word splitting of individual elements, while still expanding to multiple separate arguments.

Let's say you have three arguments: baz, foo bar and *

"$@" will expand into exactly that: baz, foo bar and *

$@ will expand into multiple other arguments: baz, foo, bar, file.txt and otherfile.jpg

Since the latter is rarely expected or desired, ShellCheck warns about it.

https://github.com/koalaman/shellcheck/wiki/SC2068

Copy link
Collaborator

Choose a reason for hiding this comment

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

I just tried it on my machine, and it seems to still work so I guess there's no problem.

@eforgacs
Copy link
Contributor Author

eforgacs commented Dec 2, 2019

@Askaholic I had never heard about black until now - is this the right link?

https://black.readthedocs.io/en/stable/

I really like the description! Can't wait to try it out!

@@ -227,7 +227,7 @@ def matchmaker_players_all_match(player_factory):
matchmaker_queue._matches = deque(matches)

async def call_shutdown():
asyncio.sleep(1)
await asyncio.sleep(1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is that await needed? If that code worked before it didn't wait for sleep anyway

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess not. TBH I'm not sure any more why I was calling shutdown like that.

@@ -121,7 +121,8 @@ def report_dirties():
# allowed to see them.
if game.visibility == VisibilityState.FRIENDS:
# To see this game, you must have an authenticated connection and be a friend of the host, or the host.
validation_func = lambda lobby_conn: lobby_conn.player.id in game.host.friends or lobby_conn.player == game.host
validation_func = lambda \
lobby_conn: lobby_conn.player.id in game.host.friends or lobby_conn.player == game.host
Copy link
Collaborator

Choose a reason for hiding this comment

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

Imho, you should leave first lambda param on same line as lambda. How do you read code? I read first input params then logic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good suggestion. I think this was a "line too long" formatting change, so I can change this to be on one line.

Copy link
Collaborator

Choose a reason for hiding this comment

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

How about just defining the function with a def? I don't see the point of using a lambda function here anyways.

@norraxx
Copy link
Collaborator

norraxx commented Dec 2, 2019

+1 for black, but if we will use black, we need to reformat whole project.

nts_client: Optional[TwilioNTS],
geoip_service: GeoIpService,
ladder_service: LadderService
address: (str, int),
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's with the double indents? I prefer single, and for what it's worth so does black

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good question. PyCharm formatted it that way, I think it's just conforming to PEP8, but I'm amenable to either single or double, no strong feelings one way or the other.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, let's keep it single then since that's what I've been doing in the rest of the code.

Copy link
Collaborator

@norraxx norraxx left a comment

Choose a reason for hiding this comment

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

ok, i've got it. 80 per line is not what we want, you have muuuch wider monotors. have at least 120 chars per row.

also, please fix sql query conditions

server/gameconnection.py Outdated Show resolved Hide resolved
server/gameconnection.py Outdated Show resolved Hide resolved
server/gameconnection.py Outdated Show resolved Hide resolved
server/gameconnection.py Outdated Show resolved Hide resolved
server/gameconnection.py Outdated Show resolved Hide resolved
server/matchmaker/algorithm.py Outdated Show resolved Hide resolved
server/matchmaker/matchmaker_queue.py Outdated Show resolved Hide resolved
server/matchmaker/matchmaker_queue.py Outdated Show resolved Hide resolved
@Askaholic
Copy link
Collaborator

@norraxx this formatting comes from black. I’m not sure I really like it either.

Also since I’m the person who spends the most time working on this code base at the moment, I feel that it is fully within reason for me to require a max line length of 80 because my screen is not as big as yours, and I prefer not to squint or constantly scroll to read full lines when I’m coding.

@norraxx
Copy link
Collaborator

norraxx commented Dec 20, 2019

well, at my job, we are up to migrate to black... we do have code changes, so we are in same situation now, and we're not so happy :-)))
80 width is rough restriction from 30 years ago

@eforgacs
Copy link
Contributor Author

Hey guys, sorry about the mess. I'm thinking about undoing this commit entirely and starting over (without using black). What are your thoughts?

@norraxx
Copy link
Collaborator

norraxx commented Dec 28, 2019

If you want, make git reset <hash of first non yours commit>, then git commit and git push force

@eforgacs
Copy link
Contributor Author

If you want, make git reset <hash of first non yours commit>, then git commit and git push force

Yes, that's actually what @Askaholic recommended as well. I'll give that a shot.

@Askaholic Askaholic merged commit ed78458 into FAForever:develop Jan 3, 2020
Brutus5000 pushed a commit that referenced this pull request Jan 27, 2020
* General code cleanup

Removing unnecessary parentheses, test for membership should be "not in", typo fixes, indentation/spacing, changing from use of deprecated functions to non-deprecated functions, capitalization, fixing syntax of Bash scripts, line length, added "await" to coroutine that is not awaited.

Changes in this commit:
- Making TestClass use CamelCase (tests/unit_tests/test_decorators.py)

* Single indenting run_lobby_server.

* Fixing SQLAlchemy query to use the correct or condition (or_)

* Changing docstrings to be comments.
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.

3 participants