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

Solving mypy errors #406

Merged
merged 3 commits into from
Oct 7, 2023
Merged

Conversation

to-sta
Copy link
Collaborator

@to-sta to-sta commented Sep 24, 2023

Contributor checklist


Description

In this PR i fixed the current errors from running mypy in the backend directory. Had to make changes in the settings.py file to solve issues that would have occured when running django with type annotations for ModelViewSets.

@andrewtavis we talked briefly in the 🌙 Code Night about internationalization and the following function:

def validate_object_existence(model, object_id):
    if model.objects.filter(id=object_id).exists():
        raise serializers.ValidationError(
            _("There is no %(model_name)s object with id %(object_id)s."),
            code="inexistent_object",
            params={"model_name": model.__name__, "object_id": object_id},
        )

# Changed to f'strings
def validate_object_existence(model: Any, object_id: Any) -> None:
    if model.objects.filter(id=object_id).exists():
        raise serializers.ValidationError(
            _(f"There is no {model.__name__} object with id {object_id}."),
            code="inexistent_object"
        )

There is no keyword argument params for ValidationError only detail and code. Since the params are only used for string formatting i changed it to an f'string. But i have not tested if the translation works. I will create an issue for that 😊.

Errors
utils\utils.py:7: error: Function is missing a type annotation  [no-untyped-def]
utils\utils.py:21: error: Function is missing a type annotation  [no-untyped-def]
utils\utils.py:29: error: Function is missing a type annotation  [no-untyped-def]
utils\utils.py:37: error: Function is missing a type annotation  [no-untyped-def]
utils\utils.py:39: error: Unexpected keyword argument "params" for "ValidationError"  [call-arg]
utils\utils.py:46: error: Function is missing a type annotation  [no-untyped-def]
utils\utils.py:48: error: Unexpected keyword argument "params" for "ValidationError"  [call-arg]
events\serializers.py:31: error: Function is missing a type annotation  [no-untyped-def]
events\serializers.py:45: error: Function is missing a return type annotation  [no-untyped-def]
events\serializers.py:51: error: Call to untyped function "isEmpty" in typed context  [no-untyped-call]      
events\serializers.py:59: error: Call to untyped function "validate_creation_and_deletion_dates" in typed context  [no-untyped-call]
events\serializers.py:60: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
events\serializers.py:65: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]      
events\serializers.py:70: error: Function is missing a type annotation  [no-untyped-def]
events\serializers.py:71: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
events\serializers.py:72: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
events\serializers.py:73: error: Call to untyped function "validate_creation_and_deprecation_dates" in typed context  [no-untyped-call]
events\serializers.py:74: error: Call to untyped function "validate_creation_and_deletion_dates" in typed context  [no-untyped-call]
events\serializers.py:79: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]      
events\serializers.py:84: error: Function is missing a type annotation  [no-untyped-def]
events\serializers.py:85: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
events\serializers.py:86: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
events\serializers.py:87: error: Call to untyped function "validate_creation_and_deprecation_dates" in typed context  [no-untyped-call]
events\serializers.py:92: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]      
events\serializers.py:97: error: Function is missing a type annotation  [no-untyped-def]
events\serializers.py:98: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
events\serializers.py:99: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
events\serializers.py:100: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
events\serializers.py:101: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
events\serializers.py:102: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
events\serializers.py:103: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
events\serializers.py:108: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]     
events\serializers.py:113: error: Function is missing a type annotation  [no-untyped-def]
events\serializers.py:114: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
events\serializers.py:115: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
events\serializers.py:116: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
events\serializers.py:117: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
events\serializers.py:122: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]     
events\serializers.py:128: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]     
events\serializers.py:133: error: Function is missing a type annotation  [no-untyped-def]
events\serializers.py:134: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
events\serializers.py:135: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
events\serializers.py:136: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
events\serializers.py:137: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
events\serializers.py:142: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]     
events\serializers.py:147: error: Function is missing a type annotation  [no-untyped-def]
events\serializers.py:148: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
events\serializers.py:149: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
events\serializers.py:154: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]     
events\serializers.py:159: error: Function is missing a type annotation  [no-untyped-def]
events\serializers.py:160: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
events\serializers.py:161: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
events\serializers.py:166: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]     
events\serializers.py:171: error: Function is missing a type annotation  [no-untyped-def]
events\serializers.py:172: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
events\serializers.py:173: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
entities\serializers.py:35: error: Function is missing a type annotation  [no-untyped-def]
entities\serializers.py:36: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
entities\serializers.py:37: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
entities\serializers.py:38: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
entities\serializers.py:39: error: Call to untyped function "validate_flags_number" in typed context  [no-untyped-call]
entities\serializers.py:40: error: Call to untyped function "validate_creation_and_deletion_dates" in typed context  [no-untyped-call]
entities\serializers.py:41: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
entities\serializers.py:46: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]    
entities\serializers.py:52: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]    
entities\serializers.py:57: error: Function is missing a type annotation  [no-untyped-def]
entities\serializers.py:58: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
entities\serializers.py:59: error: Call to untyped function "validate_creation_and_deletion_dates" in typed context  [no-untyped-call]
entities\serializers.py:64: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]    
entities\serializers.py:69: error: Function is missing a type annotation  [no-untyped-def]
entities\serializers.py:78: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
entities\serializers.py:79: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
entities\serializers.py:84: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]    
entities\serializers.py:89: error: Function is missing a type annotation  [no-untyped-def]
entities\serializers.py:98: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
entities\serializers.py:99: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
entities\serializers.py:104: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]   
entities\serializers.py:109: error: Function is missing a type annotation  [no-untyped-def]
entities\serializers.py:110: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
entities\serializers.py:111: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
entities\serializers.py:116: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]   
entities\serializers.py:121: error: Function is missing a type annotation  [no-untyped-def]
entities\serializers.py:122: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
entities\serializers.py:123: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
entities\serializers.py:124: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
entities\serializers.py:125: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
entities\serializers.py:126: error: Call to untyped function "validate_flags_number" in typed context  [no-untyped-call]
entities\serializers.py:127: error: Call to untyped function "validate_creation_and_deletion_dates" in typed context  [no-untyped-call]
entities\serializers.py:128: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
entities\serializers.py:133: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]   
entities\serializers.py:138: error: Function is missing a type annotation  [no-untyped-def]
entities\serializers.py:139: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
entities\serializers.py:140: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
entities\serializers.py:141: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
entities\serializers.py:146: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]   
entities\serializers.py:151: error: Function is missing a type annotation  [no-untyped-def]
entities\serializers.py:152: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
entities\serializers.py:153: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
entities\serializers.py:158: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]   
entities\serializers.py:163: error: Function is missing a type annotation  [no-untyped-def]
entities\serializers.py:164: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
entities\serializers.py:165: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
entities\serializers.py:170: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]   
entities\serializers.py:175: error: Function is missing a type annotation  [no-untyped-def]
entities\serializers.py:176: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
entities\serializers.py:177: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
entities\serializers.py:182: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]   
entities\serializers.py:187: error: Function is missing a type annotation  [no-untyped-def]
entities\serializers.py:188: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
entities\serializers.py:189: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
entities\serializers.py:194: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]   
entities\serializers.py:199: error: Function is missing a type annotation  [no-untyped-def]
entities\serializers.py:200: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
entities\serializers.py:201: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
content\serializers.py:17: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]     
content\serializers.py:22: error: Function is missing a type annotation  [no-untyped-def]
content\serializers.py:23: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
content\serializers.py:24: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
content\serializers.py:25: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
content\serializers.py:26: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
content\serializers.py:27: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
content\serializers.py:32: error: Call to untyped function "validate_flags_number" in typed context  [no-untyped-call]
content\serializers.py:40: error: Call to untyped function "validate_creation_and_deletion_dates" in typed context  [no-untyped-call]
content\serializers.py:45: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]     
content\serializers.py:50: error: Function is missing a type annotation  [no-untyped-def]
content\serializers.py:51: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
content\serializers.py:52: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
content\serializers.py:53: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
content\serializers.py:54: error: Call to untyped function "validate_creation_and_deletion_dates" in typed context  [no-untyped-call]
content\serializers.py:59: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]     
content\serializers.py:64: error: Function is missing a type annotation  [no-untyped-def]
content\serializers.py:65: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
content\serializers.py:66: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
content\serializers.py:78: error: Call to untyped function "validate_creation_and_deprecation_dates" in typed context  [no-untyped-call]
content\serializers.py:83: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]     
content\serializers.py:88: error: Function is missing a type annotation  [no-untyped-def]
content\serializers.py:89: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
content\serializers.py:90: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
content\serializers.py:95: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]     
content\serializers.py:100: error: Function is missing a type annotation  [no-untyped-def]
content\serializers.py:101: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
content\serializers.py:102: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
authentication\serializers.py:15: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]
authentication\serializers.py:20: error: Function is missing a type annotation  [no-untyped-def]
authentication\serializers.py:21: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
authentication\serializers.py:31: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]
authentication\serializers.py:36: error: Function is missing a type annotation  [no-untyped-def]
authentication\serializers.py:53: error: Function is missing a type annotation  [no-untyped-def]
authentication\serializers.py:54: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
authentication\serializers.py:55: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
authentication\serializers.py:56: error: Call to untyped function "validate_empty" in typed context  [no-untyped-call]
authentication\serializers.py:68: error: Call to untyped function "validate_creation_and_deletion_dates" in typed context  [no-untyped-call]
authentication\serializers.py:73: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]
authentication\serializers.py:78: error: Function is missing a type annotation  [no-untyped-def]
authentication\serializers.py:79: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
authentication\serializers.py:80: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
authentication\serializers.py:85: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]
authentication\serializers.py:90: error: Function is missing a type annotation  [no-untyped-def]
authentication\serializers.py:91: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
authentication\serializers.py:92: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
authentication\serializers.py:97: error: Missing type parameters for generic type "ModelSerializer"  [type-arg]
authentication\serializers.py:102: error: Function is missing a type annotation  [no-untyped-def]
authentication\serializers.py:103: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
authentication\serializers.py:104: error: Call to untyped function "validate_object_existence" in typed context  [no-untyped-call]
events\views.py:29: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
events\views.py:34: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
events\views.py:39: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
events\views.py:44: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
events\views.py:49: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
events\views.py:54: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
events\views.py:59: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
events\views.py:64: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
events\views.py:69: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
events\views.py:74: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
entities\views.py:37: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
entities\views.py:41: error: Function is missing a type annotation  [no-untyped-def]
entities\views.py:49: error: Function is missing a type annotation  [no-untyped-def]
entities\views.py:54: error: Function is missing a type annotation  [no-untyped-def]
entities\views.py:63: error: Function is missing a type annotation  [no-untyped-def]
entities\views.py:70: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
entities\views.py:75: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
entities\views.py:80: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
entities\views.py:85: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
entities\views.py:90: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
entities\views.py:95: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
entities\views.py:100: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
entities\views.py:105: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
entities\views.py:110: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
entities\views.py:115: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
entities\views.py:120: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
entities\views.py:125: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
content\views.py:13: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
content\views.py:18: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
content\views.py:23: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
content\views.py:28: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
content\views.py:33: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
authentication\views.py:14: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
authentication\views.py:19: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]       
authentication\views.py:24: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]       
authentication\views.py:29: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]       
authentication\views.py:34: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]       
authentication\views.py:39: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]   

I have tested running mypy and we have 0 errors at the moment. Additional i checked docker-compose up --build to see if there are any new errors introduced.

Related issue

@github-actions
Copy link
Contributor

github-actions bot commented Sep 24, 2023

Thank you for the pull request!

The activist team will do our best to address your contribution as soon as we can. The following is a checklist for maintainers to make sure this process goes as well as possible. Feel free to address the points below yourself in further commits if you realize that actions are needed :)

If you're not already a member of our public Matrix community, please consider joining! We'd suggest using Element as your Matrix client, and definitely join the General and Development rooms once you're in. It'd be great to have you!

Maintainer checklist

  • The commit messages for the remote branch should be checked to make sure the contributor's email is set up correctly so that they receive credit for their contribution

    • The contributor's name and icon in remote commits should be the same as what appears in the PR
    • If there's a mismatch, the contributor needs to make sure that the email they use for GitHub matches what they have for git config user.email in their local activist repo
  • The TypeScript and formatting workflows within the PR checks do not indicate new errors in the files changed

  • The CHANGELOG has been updated with a description of the changes for the upcoming release (if necessary)

@netlify
Copy link

netlify bot commented Sep 24, 2023

Deploy Preview for activist-org canceled.

Name Link
🔨 Latest commit 4b1aee2
🔍 Latest deploy log https://app.netlify.com/sites/activist-org/deploys/65101dfb6fd5ae0008a7ea63

@andrewtavis andrewtavis added the - Code Night 🌙 - Worked on during an activist Code Night 🌙 label Sep 25, 2023
@andrewtavis
Copy link
Member

@momanyisamuel, re message to you two on Matrix: can you give this a look through?

General question for you both, can you merge? Sorry, just have no idea what other people are seeing in here sometimes. I'd be happy to merge this post review and then I'll look into getting you two those rights :)

@andrewtavis
Copy link
Member

@to-sta, just a note that I'm on a call with @thiagogquinto right now who was working on the localizations of these. We think that the changes will work, and let's make an issue after this that will try to implement some localizations of the errors to then we can test to see if it all works 😊

@andrewtavis andrewtavis requested review from andrewtavis and removed request for momanyisamuel October 7, 2023 08:56
Copy link
Member

@andrewtavis andrewtavis left a comment

Choose a reason for hiding this comment

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

All looks great, @to-sta! Sorry for the wait on this. Am finally feeling better and a bit more caught up on things 😊

@andrewtavis andrewtavis merged commit fcb3c4c into activist-org:main Oct 7, 2023
6 of 7 checks passed
@to-sta to-sta deleted the SolvingMypyErrors branch April 21, 2024 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- Code Night 🌙 - Worked on during an activist Code Night 🌙
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants