diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 20337d83631..23827ae870d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,9 @@ repos: + - repo: https://github.com/asottile/pyupgrade + rev: v2.1.0 + hooks: + - id: pyupgrade + args: [--py37-plus] - repo: https://github.com/psf/black rev: 19.10b0 hooks: diff --git a/azure-pipelines-ci.yml b/azure-pipelines-ci.yml index 225c88b7b0f..eedeefad073 100644 --- a/azure-pipelines-ci.yml +++ b/azure-pipelines-ci.yml @@ -68,6 +68,10 @@ stages: . venv/bin/activate pre-commit run yamllint --all-files displayName: 'Run yamllint' + - script: | + . venv/bin/activate + pre-commit run pyupgrade --all-files + displayName: 'Run pyupgrade' - job: 'Validate' pool: vmImage: 'ubuntu-latest' diff --git a/docs/source/conf.py b/docs/source/conf.py index 3aa30965c95..cea9a22b64e 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- # # Home-Assistant documentation build configuration file, created by # sphinx-quickstart on Sun Aug 28 13:13:10 2016. @@ -26,7 +25,7 @@ from homeassistant.const import __short_version__, __version__ PROJECT_NAME = 'Home Assistant' PROJECT_PACKAGE_NAME = 'homeassistant' PROJECT_AUTHOR = 'The Home Assistant Authors' -PROJECT_COPYRIGHT = ' 2013-2020, {}'.format(PROJECT_AUTHOR) +PROJECT_COPYRIGHT = f' 2013-2020, {PROJECT_AUTHOR}' PROJECT_LONG_DESCRIPTION = ('Home Assistant is an open-source ' 'home automation platform running on Python 3. ' 'Track and control all devices at home and ' @@ -37,7 +36,7 @@ PROJECT_GITHUB_REPOSITORY = 'home-assistant' GITHUB_PATH = '{}/{}'.format( PROJECT_GITHUB_USERNAME, PROJECT_GITHUB_REPOSITORY) -GITHUB_URL = 'https://github.com/{}'.format(GITHUB_PATH) +GITHUB_URL = f'https://github.com/{GITHUB_PATH}' sys.path.insert(0, os.path.abspath('_ext')) @@ -132,7 +131,7 @@ def linkcode_resolve(domain, info): fn = fn[index:] - return '{}/blob/{}/{}{}'.format(GITHUB_URL, code_branch, fn, linespec) + return f'{GITHUB_URL}/blob/{code_branch}/{fn}{linespec}' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/requirements_test_pre_commit.txt b/requirements_test_pre_commit.txt index 9061a4598df..f6575ac8404 100644 --- a/requirements_test_pre_commit.txt +++ b/requirements_test_pre_commit.txt @@ -7,4 +7,5 @@ flake8-docstrings==1.5.0 flake8==3.7.9 isort==4.3.21 pydocstyle==5.0.2 +pyupgrade==2.1.0 yamllint==1.21.0 diff --git a/script/hassfest/codeowners.py b/script/hassfest/codeowners.py index 0fdb8eafb0f..2bec560f299 100644 --- a/script/hassfest/codeowners.py +++ b/script/hassfest/codeowners.py @@ -62,7 +62,7 @@ def validate(integrations: Dict[str, Integration], config: Config): codeowners_path = config.root / "CODEOWNERS" config.cache["codeowners"] = content = generate_and_validate(integrations) - with open(str(codeowners_path), "r") as fp: + with open(str(codeowners_path)) as fp: if fp.read().strip() != content: config.add_error( "codeowners", diff --git a/script/hassfest/config_flow.py b/script/hassfest/config_flow.py index 5a6f0798c51..1f14beafd73 100644 --- a/script/hassfest/config_flow.py +++ b/script/hassfest/config_flow.py @@ -68,7 +68,7 @@ def validate(integrations: Dict[str, Integration], config: Config): config_flow_path = config.root / "homeassistant/generated/config_flows.py" config.cache["config_flow"] = content = generate_and_validate(integrations) - with open(str(config_flow_path), "r") as fp: + with open(str(config_flow_path)) as fp: if fp.read().strip() != content: config.add_error( "config_flow", diff --git a/script/hassfest/model.py b/script/hassfest/model.py index c82fa670564..0a17b5aab9f 100644 --- a/script/hassfest/model.py +++ b/script/hassfest/model.py @@ -17,7 +17,7 @@ class Error: def __str__(self) -> str: """Represent error as string.""" - return "[{}] {}".format(self.plugin.upper(), self.error) + return f"[{self.plugin.upper()}] {self.error}" @attr.s diff --git a/script/hassfest/ssdp.py b/script/hassfest/ssdp.py index 28701f2b015..71e94997b0c 100644 --- a/script/hassfest/ssdp.py +++ b/script/hassfest/ssdp.py @@ -65,7 +65,7 @@ def validate(integrations: Dict[str, Integration], config: Config): ssdp_path = config.root / "homeassistant/generated/ssdp.py" config.cache["ssdp"] = content = generate_and_validate(integrations) - with open(str(ssdp_path), "r") as fp: + with open(str(ssdp_path)) as fp: if fp.read().strip() != content: config.add_error( "ssdp", diff --git a/script/hassfest/zeroconf.py b/script/hassfest/zeroconf.py index 377115f7ae4..48a5873133b 100644 --- a/script/hassfest/zeroconf.py +++ b/script/hassfest/zeroconf.py @@ -120,7 +120,7 @@ def validate(integrations: Dict[str, Integration], config: Config): zeroconf_path = config.root / "homeassistant/generated/zeroconf.py" config.cache["zeroconf"] = content = generate_and_validate(integrations) - with open(str(zeroconf_path), "r") as fp: + with open(str(zeroconf_path)) as fp: current = fp.read().strip() if current != content: config.add_error(