Skip to content

updating type hint for solutions#9

Open
tnguyen306 wants to merge 6 commits into
mainfrom
type_hinting
Open

updating type hint for solutions#9
tnguyen306 wants to merge 6 commits into
mainfrom
type_hinting

Conversation

@tnguyen306

Copy link
Copy Markdown
Collaborator

@branhoff review please

@tnguyen306 tnguyen306 requested a review from branhoff February 9, 2023 04:49
@branhoff

branhoff commented Feb 9, 2023

Copy link
Copy Markdown
Owner

Quick note, can you add common virtual environment names to the .gitignore? I see the venv got committed. Same with the .DS_Store. That should be added to the .gitignore as well.

Comment thread 02-IDE_exercises/solutions/03b-project/find_factors.py Outdated
Comment thread 02-IDE_exercises/solutions/06c-project/std_dev.py Outdated
Comment thread 02-IDE_exercises/solutions/06c-project/std_dev.py Outdated
Comment thread 02-IDE_exercises/solutions/06c-project/std_dev.py Outdated
Comment thread 02-IDE_exercises/solutions/06c-project/std_dev.py Outdated
@branhoff

branhoff commented Feb 9, 2023

Copy link
Copy Markdown
Owner

The .DS_Store. still needs to be removed and then ignored for the future.

@branhoff

branhoff commented Feb 9, 2023

Copy link
Copy Markdown
Owner

I pointed out a few, but type hints are missing for many of the variables and nearly all of the parameters in the parameter list.

g = 9.8 # velocity

return 0.5 * g * t*t
def fall_distance(t) -> float:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

missing type hint on parameter t

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

still missing type hint on parameter t

curr_num = 1
sol = 1
for i in range(n-1):
def fib(n) -> int:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

missing type hint on parameter n

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

still missing type hint on parameter n

Comment thread 02-IDE_exercises/solutions/04c-project/hailstone_step.py Outdated
Represents a taxicab that tracks the distance traveled when given x and y coordinates
"""
def __init__(self, x, y):
def __init__(self, x, y) -> None:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

missing type hint on x and y parameters

Comment thread 02-IDE_exercises/solutions/06a-project/find_median.py Outdated
Comment thread 02-IDE_exercises/solutions/06a-project/find_median.py
Comment thread 02-IDE_exercises/solutions/06a-project/find_median.py
Comment thread 02-IDE_exercises/solutions/06b-project/add_surname.py
Comment thread 02-IDE_exercises/solutions/06b-project/add_surname.py
Comment thread 02-IDE_exercises/solutions/06c-project/std_dev.py
Comment thread 02-IDE_exercises/solutions/06c-project/std_dev.py
Comment thread 02-IDE_exercises/solutions/07a-project/square_list.py Outdated
Comment thread 02-IDE_exercises/solutions/07b-project/reverse_list.py Outdated
Comment thread 02-IDE_exercises/solutions/07b-project/reverse_list.py
Comment thread 02-IDE_exercises/solutions/08a-project/count_letters.py
Comment thread 02-IDE_exercises/solutions/08a-project/count_letters.py
Comment thread 02-IDE_exercises/solutions/08b-project/words_in_both.py
Comment thread 02-IDE_exercises/solutions/08b-project/words_in_both.py
Comment thread 02-IDE_exercises/solutions/08b-project/words_in_both.py
Comment thread 02-IDE_exercises/solutions/08c-project/make_employee_dict.py
Comment thread 02-IDE_exercises/solutions/08c-project/make_employee_dict.py
Comment thread 02-IDE_exercises/solutions/09-project/AddThreeGame.py Outdated
Comment thread 02-IDE_exercises/solutions/09-project/AddThreeGame.py
Comment thread 02-IDE_exercises/solutions/09-project/AddThreeGame.py
Comment thread 02-IDE_exercises/solutions/10-project/BuildersGame.py Outdated
Comment thread 02-IDE_exercises/solutions/10-project/BuildersGame.py
Comment thread 02-IDE_exercises/solutions/10-project/BuildersGame.py Outdated
Comment thread 02-IDE_exercises/solutions/10-project/BuildersGame.py Outdated
Comment thread 02-IDE_exercises/solutions/10-project/BuildersGame.py Outdated
Comment thread 02-IDE_exercises/solutions/10-project/BuildersGame.py Outdated

@branhoff branhoff left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

You may want to use mypy: https://www.mypy-lang.org/ to check that your type hinting is correct.

Comment thread 02-IDE_exercises/solutions/03a-project/min_max_number.py Outdated
Comment thread 02-IDE_exercises/solutions/04b-project/fibonacci.py
Comment thread 02-IDE_exercises/solutions/04a-project/distance_fallen.py Outdated
Comment thread 02-IDE_exercises/solutions/07b-project/reverse_list.py Outdated
Comment thread 02-IDE_exercises/solutions/07b-project/reverse_list.py
Comment thread 02-IDE_exercises/solutions/07b-project/reverse_list.py
Comment thread 02-IDE_exercises/solutions/10-project/BuildersGame.py Outdated
Comment thread 02-IDE_exercises/solutions/10-project/BuildersGame.py
# Description: Mutates a given list and by the order of the elements of teh list

def reverse_list(lst):
def reverse_list(lst: any) -> None:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I don't believe any is a type hint. The recommendation I ready is to call object for the Any class. This should be type hinted as list[object]

# Description: Mutates a given list and by the order of the elements of teh list

def reverse_list(lst):
def reverse_list(lst: object) -> None:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

this is type hinting a parameter named lst of any type. I think you mean lst: list[object]

"""
temp_lst = []
for i in range(len(lst)-1,-1, -1):
temp_lst: object = []

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Same here. This should be temp_list: list[object] = []

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.

2 participants