For a school project I am looking for potential improvements to help contribute to open source projects. This is one I think would benefit the code style and usability of this project.
In some of the Python files, such as: kinto/kinto/schema_validation.py, there are functions with
docstrings that could be formatted better to include parameters. For example, in the following code:
def validate(data, schema):
"""Raise a ValidationError or a RefResolutionError if the data doesn't validate
with the given schema.
Note that this function is just a "wrapper" on jsonschema.validate() but with
some memoization based on the schema for better repeat performance.
"""
Because the schema is a dict, it can't be used as a hash key so it needs to be
# "transformed" to something that is hashable. The quickest solution is to convert
# it to a string.
# Note that the order of the dict will determine the string it becomes. The solution
# to that would a canonical serializer like `json.dumps(..., sort_keys=True)` but it's
# overkill since the assumption is that the schema is very unlikely to be exactly
# the same but different order.
cache_key = str(schema)
if cache_key not in _schema_cache:
# This is essentially what the `jsonschema.validate()` shortcut function does.
cls = validator_for(schema)
cls.check_schema(schema)
_schema_cache[cache_key] = cls(schema)
return _schema_cache[cache_key].validate(data)
The above function could be re-written in the format below:
def some_function(argument1):
"""Summary or Description of the Function
Parameters:
argument1 (int): Description of arg1
Returns:
int:Returning value
For a school project I am looking for potential improvements to help contribute to open source projects. This is one I think would benefit the code style and usability of this project. In some of the Python files, such as: kinto/kinto/schema_validation.py, there are functions with docstrings that could be formatted better to include parameters. For example, in the following code:
def validate(data, schema): """Raise a ValidationError or a RefResolutionError if the data doesn't validate with the given schema. Note that this function is just a "wrapper" on
jsonschema.validate()
but with some memoization based on the schema for better repeat performance. """Because the schema is a dict, it can't be used as a hash key so it needs to be
The above function could be re-written in the format below:
def some_function(argument1): """Summary or Description of the Function
"""
----https://www.datacamp.com/community/tutorials/docstrings-python