-
Notifications
You must be signed in to change notification settings - Fork 63
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
General code cleanup #507
Conversation
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.
tests/unit_tests/test_decorators.py
Outdated
@@ -7,7 +7,7 @@ | |||
|
|||
def test_with_logger(): | |||
@with_logger | |||
class testclass(): | |||
class testclass: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be camel case
There was a problem hiding this comment.
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)
There was a problem hiding this 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 "$@" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@Askaholic I had never heard about 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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
server/__init__.py
Outdated
@@ -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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
+1 for black, but if we will use black, we need to reformat whole project. |
server/__init__.py
Outdated
nts_client: Optional[TwilioNTS], | ||
geoip_service: GeoIpService, | ||
ladder_service: LadderService | ||
address: (str, int), |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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
@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. |
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 :-))) |
Hey guys, sorry about the mess. I'm thinking about undoing this commit entirely and starting over (without using black). What are your thoughts? |
If you want, make |
Yes, that's actually what @Askaholic recommended as well. I'll give that a shot. |
* 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.
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.