Adding Mypy type annotations to domain folder files
See original GitHub issueThis issue will track the type annotation process of all the core/domain/*.py
(and their test files). To get started, ask to be assigned to any unclaimed task. Tasks are claimed by adding the username of the claimer to the end of the task, e.g. @example.
Note: Main code file and its test file must be type-annotated together.
The general procedure to add type annotations is as follows:
- Start with the main code file first.
- Remove the file to be annotated from the mypy denylist (i.e. from
NOT_FULLY_COVERED_FILES
inscripts/run_mypy_checks.py
). Run the mypy checks on the code file usingpython -m scripts.run_mypy_checks --files <path/to/file>
to understand all the errors mypy is reporting for this file. - Go over them one by one, and fix them by following the detailed instructions as mentioned in our wiki.
- PAY ATTENTION to our guidelines for using type ignores in the codebase.
- For testing the changes after annotating all the files, run
python -m scripts.run_mypy_checks
, which runs the type checks on the entire codebase, and ensure that no errors are being reported. - If errors occur in other files due to you change make sure to also fix those other files.
Good examples of already annotated files in the codebase:
- Check out the
core/storage
folder. - Ref PR for domain file type annotation: #14034
If you face problems in understanding a particular case while adding annotations, please go over the tips mentioned in the wiki once, and let us know if you are still stuck!
Tasks/files:
-
core/domain/action_registry.py
@sahiljoster32 -
core/domain/activity_services.py
@sahiljoster32 -
core/domain/auth_services.py
@IamhappyXD -
core/domain/blog_services.py
@IamhappyXD -
core/domain/calculation_registry.py
@sahiljoster32 -
core/domain/classifier_services.py
-
core/domain/classroom_services.py
@SD-13 -
core/domain/collection_services.py
-
core/domain/config_services.py
@sahiljoster32 -
core/domain/cron_services.py
@SD-13 -
core/domain/customization_args_util.py
-
core/domain/draft_upgrade_services.py
-
core/domain/email_manager.py
-
core/domain/email_services.py
@jordyparker -
core/domain/email_subscription_services.py
@sahiljoster32 -
core/domain/event_services.py
-
core/domain/exp_fetchers.py
-
core/domain/exp_services.py
-
core/domain/expression_parser.py
-
core/domain/feedback_services.py
-
core/domain/fs_services.py
@sahiljoster32 -
core/domain/html_cleaner.py
@SD-13 -
core/domain/html_validation_service.py
-
core/domain/image_services.py
@gopivaibhav -
core/domain/image_validation_services.py
@hsadia538 -
core/domain/improvements_services.py
-
core/domain/interaction_registry.py
-
core/domain/learner_goals_services.py
-
core/domain/learner_playlist_services.py
-
core/domain/learner_progress_services.py
-
core/domain/moderator_services.py
-
core/domain/object_registry.py
-
core/domain/opportunity_services.py
-
core/domain/platform_feature_services.py
-
core/domain/platform_parameter_list.py
@Darsuu -
core/domain/platform_parameter_list_test.py
@Darsuu -
core/domain/platform_parameter_registry.py
@Darsuu -
core/domain/playthrough_issue_registry.py
@Darsuu -
core/domain/question_fetchers.py
@winnie368c -
core/domain/question_services.py
-
core/domain/rating_services.py
@IamhappyXD -
core/domain/recommendations_services.py
-
core/domain/rights_manager.py
-
core/domain/role_services.py
@gopivaibhav -
core/domain/rte_component_registry.py
@hsadia538 -
core/domain/rules_registry.py
@hsadia538 -
core/domain/search_services.py
-
core/domain/skill_fetchers.py
-
core/domain/skill_services.py
-
core/domain/stats_services.py
-
core/domain/story_fetchers.py
-
core/domain/story_services.py
-
core/domain/subscription_services.py
-
core/domain/subtopic_page_services.py
@ashish-patwal -
core/domain/suggestion_registry.py
-
core/domain/suggestion_services.py
-
core/domain/summary_services.py
-
core/domain/takeout_service.py
@jordyparker -
core/domain/taskqueue_services.py
@jordyparker -
core/domain/topic_fetchers.py
@SD-13 -
core/domain/topic_services.py
@SD-13 -
core/domain/translatable_object_registry.py
@ashish-patwal -
core/domain/translation_fetchers.py
@sahiljoster32 -
core/domain/translation_services.py
@sahiljoster32 -
core/domain/user_query_services.py
@SD-13 -
core/domain/user_services.py
@SD-13 -
core/domain/visualization_registry.py'
@SD-13 -
core/domain/voiceover_services.py
@SD-13 -
core/domain/wipeout_service.py
@SD-13 -
core/domain/change_domain.py
@div-yam -
core/domain/collection_domain.py
@sahiljoster32 -
core/domain/exp_domain.py
@Yavnikaa -
core/domain/fs_domain.py
@PranshuSrivastava -
core/domain/param_domain.py
@Asmit2952 (attempted in #14302) -
core/domain/platform_parameter_domain.py
@Asmit2952 (attempted in #14302) -
core/domain/question_domain.py
@Asmit2952 (attempted in #14302) -
core/domain/skill_domain.py
@dhruvshrivastava -
core/domain/state_domain.py
@dhruvshrivastava -
core/domain/stats_domain.py
@winnie368c -
core/domain/story_domain.py
@Sangkyun-Kim15 -
core/domain/subtopic_page_domain.py
@ashish-patwal -
core/domain/user_domain.py
@sahiljoster32 -
core/domain/user_query_domain.py
@ashish-patwal
Issue Analytics
- State:
- Created 2 years ago
- Comments:242 (182 by maintainers)
Top Results From Across the Web
mypy: Add type annotations to 'nova.pci' - OpenDev
The 'nova.pci' module is poorly understood and difficult to debug. Start adding type hints to make this a little easier to parse and...
Read more >Using mypy with an existing codebase
Using mypy with an existing codebase#. This section explains how to get started using mypy with an existing, significant codebase that has little...
Read more >how to explain domain specific constraints to mypy
1 Answer 1 ; : return my_dict.get('a') ; : ret_val = my_dict.get('a') or my_dict[ ; : return cast(int, my_dict.get( ...
Read more >PEP 561 – Distributing and Packaging Type Information
“Module” a file containing Python runtime code or stubbed type information. “Package” a directory or directories that namespace Python modules.
Read more >Python Static Type Checking with Mypy - Linode
You can configure Mypy using a configuration file named mypy.ini . ... Any mypy command launched in that directory behaves as though it's...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think the
Mapping
is wrong as the value of field with key'filters'
should beList[Dict[…]]
orList[SomeTypedDict]]
. Also, use more descriptive naming for theTypedDict
and use the class installation ofTypedDict
, so in your case:Also, you don’t seem to be assigned to that file, so not sure why are you working on it.
I think you should use the alternative syntax for TypedDict’s and define the TypedDicts at a top of a file. So if we have a function that returns{'id': 'abcd', 'active': True, 'count': 1}
and represent for example some kind of counter then the type variable should beCounter = TypedDict('Counter', {'id': str, 'active': bool, 'count': int})
Let’s use the class syntax. So if we have a function that returns
{'id': 'abcd', 'active': True, 'count': 1}
and represent for example some kind of counter then the class should be