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 mypy to the GitHub Action for tests and fixed types in the whole project #655

Merged
merged 18 commits into from
Mar 10, 2024

Conversation

estebanx64
Copy link
Contributor

No description provided.

@estebanx64 estebanx64 changed the title 🏷️ Add mypy to the GitHub Action for tests 🏷️ Add mypy to the GitHub Action for tests and fixed types in the whole project Mar 8, 2024
Copy link
Member

@tiangolo tiangolo left a comment

Choose a reason for hiding this comment

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

Cool! I updated a couple of things and it's ready now.

I reverted the types in alembic, as that code is autogenerated and will keep increasing, without types. 🥲 ...and it's also excluded from mypy, so it's fine to leave it as is.

I updated the delete_user endpoint to move the errors to the top and put the main code outside of an if block.

I updated a bit the settings, there's a couple extra things to do but it's fine for now. I updated it to read from the .env file.

session.delete(user)
session.commit()
return Message(message="User deleted successfully")
elif user == current_user and current_user.is_superuser:
raise HTTPException(
status_code=403, detail="Super users are not allowed to delete themselves"
)

return Message(message="User does not match the conditions to be deleted")
Copy link
Member

Choose a reason for hiding this comment

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

I was checking this part, and I see it would be better to move the errors to the top, error out early, that way the rest of the "happy path" of the code can run outside of any if statements.

This also handles that this last Message would be returned as a 200 OK, but it should be an error... although this line would really never be reached. By refactoring the code this way, there's no need to do tricks to convince mypy that it's all good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yes, sorry I forgot to add the status code 400 at that response

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was a lot better the refactor you made, thanks!

@tiangolo tiangolo merged commit a230f4f into master Mar 10, 2024
3 checks passed
@tiangolo tiangolo deleted the FL-39-mypy-types-fix branch March 10, 2024 19:47
@tiangolo
Copy link
Member

Thanks! 🚀 ☕

gusevyaroslove pushed a commit to gusevyaroslove/fastapi-template that referenced this pull request Aug 4, 2024
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