-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Fix part of #14033: Added Mypy type annotations to some files. #14469
Changes from 1 commit
d74038b
354d901
7930e4f
2ff1fcb
7da71af
6afee7e
f6a3c12
5dc96d8
bffe408
f65c8ba
39fbb95
c34365a
7fec54c
1885375
9667b75
13f1b09
8a67ca0
c4c2a94
44a0126
d11cfaf
62b2e5e
9b7a5b5
fe36b85
fd656c8
28669b1
94084f6
601d151
44e8825
2e91bd8
c647552
20c8315
176807f
5252178
6b6ead6
6a3f29b
1d19b94
4d29919
a85bc4f
3d99ce3
53a8d9a
e4017ee
9537ed6
b943be9
2f62fd9
c71a403
d0a9978
4ca7c69
2840a8a
69cac5d
995563c
c0b4738
b299913
085e97e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
|
||
import collections | ||
import copy | ||
import datetime | ||
import json | ||
import re | ||
import string | ||
|
@@ -41,6 +42,8 @@ | |
from core.domain import state_domain | ||
from core.platform import models | ||
|
||
from typing import Any, Dict | ||
|
||
(exp_models,) = models.Registry.import_models([models.NAMES.exploration]) | ||
|
||
|
||
|
@@ -620,11 +623,13 @@ def __init__( | |
|
||
@classmethod | ||
def create_default_exploration( | ||
cls, exploration_id, title=feconf.DEFAULT_EXPLORATION_TITLE, | ||
init_state_name=feconf.DEFAULT_INIT_STATE_NAME, | ||
category=feconf.DEFAULT_EXPLORATION_CATEGORY, | ||
objective=feconf.DEFAULT_EXPLORATION_OBJECTIVE, | ||
language_code=constants.DEFAULT_LANGUAGE_CODE): | ||
cls, exploration_id: str, | ||
title: str=feconf.DEFAULT_EXPLORATION_TITLE, | ||
init_state_name: str=feconf.DEFAULT_INIT_STATE_NAME, | ||
category: str=feconf.DEFAULT_EXPLORATION_CATEGORY, | ||
objective: str=feconf.DEFAULT_EXPLORATION_OBJECTIVE, | ||
language_code: str=constants.DEFAULT_LANGUAGE_CODE | ||
) -> Exploration: | ||
vojtechjelinek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Returns a Exploration domain object with default values. | ||
|
||
'title', 'init_state_name', 'category', 'objective' if not provided are | ||
|
@@ -661,9 +666,11 @@ def create_default_exploration( | |
|
||
@classmethod | ||
def from_dict( | ||
cls, exploration_dict, | ||
exploration_version=0, exploration_created_on=None, | ||
exploration_last_updated=None): | ||
cls, exploration_dict: Dict[str, Any], | ||
exploration_version: int =0, | ||
exploration_created_on: datetime.datetime=None, | ||
exploration_last_updated: datetime.datetime=None | ||
) -> Exploration: | ||
"""Return a Exploration domain object from a dict. | ||
|
||
Args: | ||
|
@@ -2327,7 +2334,7 @@ def to_yaml(self): | |
|
||
return python_utils.yaml_from_dict(exp_dict) | ||
|
||
def to_dict(self): | ||
def to_dict(self) -> Dict[str, Any]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the typing, please. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
"""Returns a copy of the exploration as a dictionary. It includes all | ||
necessary information to represent the exploration. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,8 @@ | |
from core.domain import html_cleaner | ||
from core.domain import html_validation_service | ||
|
||
from typing import Any, Dict | ||
|
||
vojtechjelinek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Do not modify the values of these constants. This is to preserve backwards | ||
# compatibility with previous change dicts. | ||
STORY_PROPERTY_TITLE = 'title' | ||
|
@@ -861,7 +863,7 @@ def has_exploration(self, exp_id): | |
return True | ||
return False | ||
|
||
def to_dict(self): | ||
def to_dict(self) -> Dict[str, Any]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the typing and add ignore to the callsite There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done! |
||
"""Returns a dict representing this Story domain object. | ||
|
||
Returns: | ||
|
@@ -976,8 +978,9 @@ def from_dict( | |
|
||
@classmethod | ||
def create_default_story( | ||
cls, story_id, title, description, corresponding_topic_id, | ||
url_fragment): | ||
cls, story_id: str, title: str, | ||
description: str, corresponding_topic_id: str, | ||
url_fragment: str) -> Story: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the typing and add ignore to the callsite There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done! |
||
"""Returns a story domain object with default values. This is for | ||
the frontend where a default blank story would be shown to the user | ||
when the story is created for the first time. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,8 @@ | |
from core.domain import subtopic_page_domain | ||
from core.domain import user_services | ||
|
||
from typing import Any, Dict | ||
|
||
CMD_CREATE_NEW = feconf.CMD_CREATE_NEW | ||
CMD_CHANGE_ROLE = feconf.CMD_CHANGE_ROLE | ||
CMD_REMOVE_MANAGER_ROLE = feconf.CMD_REMOVE_MANAGER_ROLE | ||
|
@@ -561,7 +563,7 @@ def __init__( | |
self.practice_tab_is_displayed = practice_tab_is_displayed | ||
self.page_title_fragment_for_web = page_title_fragment_for_web | ||
|
||
def to_dict(self): | ||
def to_dict(self) -> Dict[str, Any]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the typing and add ignore to the callsite There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done! |
||
"""Returns a dict representing this Topic domain object. | ||
|
||
Returns: | ||
|
@@ -1132,7 +1134,8 @@ def validate(self, strict=False): | |
|
||
@classmethod | ||
def create_default_topic( | ||
cls, topic_id, name, url_fragment, description): | ||
cls, topic_id: str, name: str, url_fragment: str, description: str | ||
) -> Topic: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the typing and add ignore to the callsite There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done! |
||
"""Returns a topic domain object with default values. This is for | ||
the frontend where a default blank topic would be shown to the user | ||
when the topic is created for the first time. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this ignore needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar to above, but here we are invoking method on object which was returned by
deserialize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mytype don't know that this is mapped with function object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again I think if you type the
SERIALIZE_FUNCTIONS
it should helpThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in
SERIALIZE_FUNCTIONS
keys are str, but every value is lambda functions. so, every function returns string using serialize method on object. like :-if we call
CACHE_NAMESPACE_SKILL
onSERIALIZE_FUNCTIONS
it returns JSON-encoded str encoding all of the information composing the skill object.oppia/core/domain/caching_services.py
Line 98 in f4bc551
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall i create a new function taking
lambda x: x.serialize()
as body of that function and return that x as a casted string, then call that function on everySERIALIZATION_FUNCTIONS
's value.Then assign
SERIALIZATION_FUNCTIONS
dict[str, str]is that ok ??!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean, it should be possible to just type the serialize function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!, ignore stmt removed.