Skip to content

Instantly share code, notes, and snippets.

@gonzalodiaz
gonzalodiaz / restructuredtext.py
Last active June 6, 2020 09:08
reStructuredText
class World:
"""Class to contain the properties of the World.
:param yearly_population: World's population by year
:type arg: dict
:ivar yearly_population: Internal attribute to hold the world population.
:vartype yearly_population: dict
"""
class World:
"""Class to contain the properties of the World.
Args:
yearly_population (dict): World's population by year
Attributes:
yearly_population (dict): Internal attribute to hold the world population.
"""
class World:
"""Class to contain the properties of the World.
Parameters
----------
yearly_population : dict
World's population by year
Attributes
----------
class World:
"""Class to contain the properties of the World.
:param yearly_population: World's population by year
:ivar yearly_population: Internal attribute to hold the world population.
"""
def __init__(self, yearly_population: dict):
self.yearly_population: dict = yearly_population
[flake8]
# W291 trailing whitespace
# W292 no newline at end of file
# W293 blank line contains whitespace
# E203 whitespace before ':'
ignore = W291,W292,W293,E203
max-line-length = 100
max-complexity = 10
@gonzalodiaz
gonzalodiaz / tox.ini
Created June 6, 2020 09:15
ToxIniFull
[flake8]
# W291 trailing whitespace
# W292 no newline at end of file
# W293 blank line contains whitespace
# E203 whitespace before ':'
ignore = W291,W292,W293,E203
max-line-length = 100
max-complexity = 10
[pydocstyle]
class World:
"""Class to contain the properties of the World.
:param yearly_population: World's population by year
:ivar yearly_population: Internal attribute to hold the world population.
"""
def __init__(self, yearly_population: dict):
self.yearly_population: dict = yearly_population
@gonzalodiaz
gonzalodiaz / population_fix.py
Last active June 6, 2020 09:19
PopulationFix
def population(self, year: int) -> int:
"""Obtain the population in the world for a given year.
:param year: Year of which the population wants to be known.
:returns: Population for that year. 0 if the year was not found.
"""
return self.yearly_population.get(year, 0)
def population_on_2020(self) -> int:
@gonzalodiaz
gonzalodiaz / environment.yml
Created June 6, 2020 09:20
EnvironmentYml
name: tutorial-python-quality-code-env
channels:
- defaults
- conda-forge
dependencies:
- python=3.8.3
- flake8=3.8.2
- pydocstyle=4.0.1
- mypy=0.770
- black=19.10b
#! /bin/bash -e
environment_header=$(head -n 1 environment.yml)
environment_name=${environment_header/name: /}
conda remove --yes --quiet -n "${environment_name}" --all
conda env create --quiet --force -f environment.yml