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

Expected Indents #3

Open
wants to merge 136 commits into
base: main
Choose a base branch
from
Open

Expected Indents #3

wants to merge 136 commits into from

Conversation

janine9vn
Copy link
Contributor

No description provided.

dhananjaylatkar and others added 27 commits September 9, 2023 21:18
added SVD and winning and loosing functionality
Updated words.json, minor bug fix in game.py - Game._get_random_word()
final fixes before welcome image
Docstring update + welcome image
…81667954'

git-subtree-dir: expected-indents
git-subtree-mainline: 4bae50a
git-subtree-split: 24e2711
Comment on lines +28 to +35
/*
I forgot exactly how we decided the API response should be... so I assume it's like this:
{
"word": "w_r_",
"lives": 5,
"image": "https://example.com/image.png"
}
*/
Copy link

Choose a reason for hiding this comment

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

This comment is a bit worrying, both it existing in first place as well as it still being there in the PR

@etrotta
Copy link

etrotta commented Oct 1, 2023

Some notes that are not specific to any files, but overall recommendations:
(not requirements from the code jam, but personal recommendations from me)

  • use unit tests
  • use type hints on function definitions
  • always use absolute imports over relative imports

Also, it might look like I reviewed extremely fast, but I took notes before officially starting the review - much of it was copy/pasting from the notes

Copy link

@etrotta etrotta left a comment

Choose a reason for hiding this comment

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

forgot to actually Submit the review, sorry

str: A random uid.
"""
characters = string.ascii_letters + string.digits
chars = [secrets.choice(characters) for _ in range(length)]
Copy link

Choose a reason for hiding this comment

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

Why secrets.choice instead of random.choices?

Personally I'd probably just use an uuid.UUID4 instead to be honest

def __init__(self, lives=6):
self.word = self._get_random_word()
# print(self.word)
self.total_lives = lives # const
Copy link

Choose a reason for hiding this comment

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

Unused variable? (total_lives)

Comment on lines +61 to +62
script_dir = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(script_dir, 'nouns-clear.txt')
Copy link

Choose a reason for hiding this comment

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

Use pathlib over os.path.
Arguably personal preferences, specially since it should work in any OS using either, but I still recommend pathlib over it

"""
script_dir = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(script_dir, 'nouns-clear.txt')
with open(file_path) as nounfile:
Copy link

Choose a reason for hiding this comment

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

Preferably specify the mode and encoding whenever you're opening a file

The encoding doesn't matters much when all of the text in the file is ASCII, but the default encoding is currently platform dependent, the default encoding for Windows may change in the future, and I personally believe that it's better to explicit state the mode even when using the default ('r')



class Game:
"""game class"""
Copy link

Choose a reason for hiding this comment

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

May as well not have a docstring over just the name of the class. The comments in init could be a bit tidier, but are passable

image = image.resize((self.size, self.size))
self.A = np.array(image)

def reduce(self, terms, type=np.uint8):
Copy link

Choose a reason for hiding this comment

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

avoid using built-in names such as type as a variable name, for example you could use dtype here matching numpy's terminology

type (numpy type, optional): Type of the returned array. Defaults to np.uint8.

Returns:
_type_: _description_
Copy link

Choose a reason for hiding this comment

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

forgot to change this? (line 76)

Comment on lines +40 to +41
Raises:
AssertionError: Game must exist, game_id must be a key the games dictionary.
Copy link

Choose a reason for hiding this comment

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

In multiple docstrings you have "Raises AssetionError", but you do not actually use assert in any of these places?
Side note: overall you might want to avoid using assert (not that you have any in this project rn) and normally raise exceptions instead, in part since assert is skipped if you use optimization command line arguments when running python (-OO), in part so that you and other people using your code can catch them based on their type with except:


app = Flask(__name__)

games = dict()
Copy link

Choose a reason for hiding this comment

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

Avoid using global variables, use Flask's Application Context instead.

Global variables are bug prone overall, specially in multi-threaded contexts
Also, you do not need to use the global keyword to modify global variables, only to overwrite them. Do not use global variables either way though.

- Run `src/server.py` using python
- In your browser, go to [`http://127.0.0.1:5000`](http://127.0.0.1:5000)
### OR Visit the website:
[http://picturepuzzlers.pythonanywhere.com/](http://picturepuzzlers.pythonanywhere.com/ "http://picturepuzzlers.pythonanywhere.com/")
Copy link

Choose a reason for hiding this comment

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

No need to use []() as far as I know? Just put it normally

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.

7 participants