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

Iron out type-checking and formatting #138

Merged
merged 14 commits into from
May 16, 2024

Conversation

Samuel-Therrien-Beslogic
Copy link
Contributor

@Samuel-Therrien-Beslogic Samuel-Therrien-Beslogic commented May 8, 2024

Please merge #144 first


  • We weren't using the mypy plugin, oops! Type-checking with mypy is now a lot more aware of our models. Unfortunately doesn't help Pyright/Pylance (Pylance is what runs in the IDE).
  • Added missing djangorestframework-stubs
  • Turn on strict typing in mypy
  • Added a Request model to type the request param in our methods. This mainly allows to get our User model from
  • Added missing generic type parameters
  • Bumped checker tools versions
  • Bumped drf-spectacular
  • Removed dev-only requirements accidentally added to requirements in Authentication added  #82
  • Split type: ignore from pyright: ignore comments
  • Removed unused serializers.SitePatchSerializer

Cross-referencing upstream issues:

@Samuel-Therrien-Beslogic Samuel-Therrien-Beslogic force-pushed the iron-out-type-checking-and-linting branch from 8f8111e to a7d19dd Compare May 8, 2024 22:21
Comment on lines +20 to +21
@classmethod
def from_string(cls, value: str):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

CC @NicolasDontigny This is how you do a classmethod in Python (ie: a method you call on the class itself, this is technically different than a static method, but this would be a static method in other languages)

Comment on lines 45 to 47
# Missing "id" in "Model" or some base "User" class?
if TYPE_CHECKING:
id: int
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if missing from upstream type stubs or if we're doing something specific to have an id on our user.

Comment on lines +338 to +341
# TODO: Are we sure about getlist ?
# If this is correct, consider raising an issue upstream
for tree_type_json in request.data.getlist("species"): # type:ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@BesOlivierBouchard Since you added this. Can you validate whether this is valid code?

Copy link
Contributor

Choose a reason for hiding this comment

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

From what I saw online, this is the way to retrieve a "list" from "data". Doing it with the get() or the data[] will not work properly.

try:
post = Post.objects.get(pk=postId)
except Post.DoesNotExist:
return Response(status="sef")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think "sef" status was intended? I went with HTTP_404_NOT_FOUND by combining the try-except

@BesOlivierBouchard BesOlivierBouchard merged commit 56aca92 into main May 16, 2024
7 checks passed
@BesOlivierBouchard BesOlivierBouchard deleted the iron-out-type-checking-and-linting branch May 16, 2024 17:26
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