The Wayback Machine - https://web.archive.org/web/20200915035031/https://github.com/PythonFreeCourse/lms/pull/52
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

add more informative error messages to common errors #52

Draft
wants to merge 1 commit into
base: master
from

Conversation

@itraviv
Copy link
Collaborator

itraviv commented Apr 11, 2020

during upload of exercises

during upload of exercises
@@ -6,7 +6,7 @@
)
from playhouse.migrate import PostgresqlMigrator, SqliteMigrator # noqa: I201

DB_NAME = os.getenv('DB_NAME', 'lms')
DB_NAME = os.getenv('DB_NAME', 'db')

This comment has been minimized.

@yammesicka

yammesicka Apr 13, 2020

Member

Maaan what are you doin'

_header_parts = header.split()
if len(_header_parts) < 2:
err = (
f'invalid "{_UPLOAD_KEYWORD}" - got "{header}" - '

This comment has been minimized.

@yammesicka

yammesicka Apr 13, 2020

Member

Start sentences with a capital letter

_MATCHER_THRESHOLD = 0.7


def get_similarity(header: str) -> Tuple[str, str]:

This comment has been minimized.

@yammesicka

yammesicka Apr 13, 2020

Member

Just return an Optional[str]



def get_similarity(header: str) -> Tuple[str, str]:
if not header:

This comment has been minimized.

@yammesicka

yammesicka Apr 13, 2020

Member

Special cases aren't special enough to break the rules (if len < 2 is enough)

@@ -314,9 +318,12 @@ def upload():
identical_tests_tasks.solve_solution_with_identical_code.apply_async(
args=(solution.id,))
matches.add(exercise_id)
if not matches:
errors.append("no # Upload <exercise num> headers found!")

This comment has been minimized.

@yammesicka

yammesicka Apr 13, 2020

Member

No with a capital N. Remove !

return jsonify({
'exercise_matches': list(matches),
'exercise_misses': list(misses),
'errors': errors

This comment has been minimized.

@yammesicka

yammesicka Apr 13, 2020

Member

Add trailing ,

) -> Iterator[Tuple[str, str]]:
return filter(lambda x: x[0], map(get_exercise, (c for c in cells)))
return filter(lambda x: x[1], map(get_exercise, (c for c in cells)))

This comment has been minimized.

@yammesicka

yammesicka Apr 13, 2020

Member

Use itemgetter

@@ -17,19 +41,25 @@ def get_code_cells(notebook_data: Notebook) -> Iterator[Cell]:


def get_exercise(cell: Cell) -> Tuple[str, str]:
# return exercise_id, exercise_code for matched exercises
# return error message in second argument
# if nothing found return both empty
code: List[str] = cell.get('source', [])

This comment has been minimized.

@yammesicka

yammesicka Apr 13, 2020

Member

Maybe add itertools.dropwhile(lambda line: line.strip() == '', code)?

_upload_header = _header_parts[0].lower()
s_matcher = difflib.SequenceMatcher(None, _upload_header, _UPLOAD_KEYWORD.lower())
typo_msg = (
f"You have a typo in {header} - "

This comment has been minimized.

@yammesicka

yammesicka Apr 13, 2020

Member

It's better to leave the strings to the frontend. Maybe we should create enum file somewhere(?)

@itraviv itraviv marked this pull request as draft Jun 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.
HTTPS · web.archive.org
← Home