Enable T20 (flake8-print) to ban use of print statements (#86525)

* Enable T20 (flake8-print) to ban use of print statements

* Make compatible with flake8 config
This commit is contained in:
Franck Nijhof 2023-01-24 14:24:21 +01:00 committed by GitHub
parent c9499f6574
commit 73c4ac53d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 24 additions and 30 deletions

View file

@ -330,7 +330,7 @@ async def async_ensure_config_exists(hass: HomeAssistant) -> bool:
if os.path.isfile(config_path): if os.path.isfile(config_path):
return True return True
print( print( # noqa: T201
"Unable to find configuration. Creating default one in", hass.config.config_dir "Unable to find configuration. Creating default one in", hass.config.config_dir
) )
return await async_create_default_config(hass) return await async_create_default_config(hass)
@ -384,7 +384,7 @@ def _write_default_config(config_dir: str) -> bool:
return True return True
except OSError: except OSError:
print("Unable to create default configuration file", config_path) print("Unable to create default configuration file", config_path) # noqa: T201
return False return False

View file

@ -262,6 +262,7 @@ select = [
"D", # docstrings "D", # docstrings
"E", # pycodestyle "E", # pycodestyle
"F", # pyflakes/autoflake "F", # pyflakes/autoflake
"T20", # flake8-print
"W", # pycodestyle "W", # pycodestyle
"UP", # pyupgrade "UP", # pyupgrade
"PGH004", # Use specific rule codes when using noqa "PGH004", # Use specific rule codes when using noqa
@ -278,5 +279,10 @@ select = [
"homeassistant/components/mqtt/discovery.py" = ["C901"] "homeassistant/components/mqtt/discovery.py" = ["C901"]
"homeassistant/components/websocket_api/http.py" = ["C901"] "homeassistant/components/websocket_api/http.py" = ["C901"]
# Allow for main entry & scripts to write to stdout
"homeassistant/__main__.py" = ["T201"]
"homeassistant/scripts/*" = ["T201"]
"script/*" = ["T20"]
[tool.ruff.mccabe] [tool.ruff.mccabe]
max-complexity = 25 max-complexity = 25

View file

@ -21,3 +21,13 @@ ignore =
D202, D202,
W504 W504
noqa-require-code = True noqa-require-code = True
# Ignores, that are currently caused by mismatching configurations
# between ruff and flake8 configurations. Once ruff becomes permanent flake8
# will be removed, including these ignores below.
# In case we decide not to continue with ruff, we should remove these
# and probably need to clean up a couple of noqa comments.
per-file-ignores =
homeassistant/config.py:NQA102
tests/components/tts/conftest.py:NQA102
tests/helpers/test_icon.py:NQA102

View file

@ -1587,9 +1587,6 @@ async def test_multiple_instances_with_tls_v12(hass):
) )
await hass.async_block_till_done() await hass.async_block_till_done()
import pprint
pprint.pprint(result2)
assert result2["type"] == "create_entry" assert result2["type"] == "create_entry"
assert result2["title"] == "guest_house" assert result2["title"] == "guest_house"
assert result2["data"] == { assert result2["data"] == {

View file

@ -55,9 +55,9 @@ def empty_cache_dir(tmp_path, mock_init_cache_dir, mock_get_cache_files, request
return return
# Print contents of dir if failed # Print contents of dir if failed
print("Content of dir for", request.node.nodeid) print("Content of dir for", request.node.nodeid) # noqa: T201
for fil in tmp_path.iterdir(): for fil in tmp_path.iterdir():
print(fil.relative_to(tmp_path)) print(fil.relative_to(tmp_path)) # noqa: T201
# To show the log. # To show the log.
assert False assert False

View file

@ -166,7 +166,6 @@ async def test_1st_discovers_2nd_component(hass):
async def component1_setup(hass, config): async def component1_setup(hass, config):
"""Set up mock component.""" """Set up mock component."""
print("component1 setup")
await discovery.async_discover( await discovery.async_discover(
hass, "test_component2", {}, "test_component2", {} hass, "test_component2", {}, "test_component2", {}
) )

View file

@ -16,7 +16,7 @@ def test_battery_icon():
iconbase = "mdi:battery" iconbase = "mdi:battery"
for level in range(0, 100, 5): for level in range(0, 100, 5):
print( print( # noqa: T201
"Level: %d. icon: %s, charging: %s" "Level: %d. icon: %s, charging: %s"
% ( % (
level, level,

View file

@ -183,12 +183,6 @@ def test_norway_in_june(hass):
june = datetime(2016, 6, 1, tzinfo=dt_util.UTC) june = datetime(2016, 6, 1, tzinfo=dt_util.UTC)
print(sun.get_astral_event_date(hass, SUN_EVENT_SUNRISE, datetime(2017, 7, 25)))
print(sun.get_astral_event_date(hass, SUN_EVENT_SUNSET, datetime(2017, 7, 25)))
print(sun.get_astral_event_date(hass, SUN_EVENT_SUNRISE, datetime(2017, 7, 26)))
print(sun.get_astral_event_date(hass, SUN_EVENT_SUNSET, datetime(2017, 7, 26)))
assert sun.get_astral_event_next(hass, SUN_EVENT_SUNRISE, june) == datetime( assert sun.get_astral_event_next(hass, SUN_EVENT_SUNRISE, june) == datetime(
2016, 7, 24, 22, 59, 45, 689645, tzinfo=dt_util.UTC 2016, 7, 24, 22, 59, 45, 689645, tzinfo=dt_util.UTC
) )

View file

@ -24,21 +24,13 @@ async def test_component_dependencies(hass):
mock_integration(hass, MockModule("mod1", ["mod3"])) mock_integration(hass, MockModule("mod1", ["mod3"]))
with pytest.raises(loader.CircularDependency): with pytest.raises(loader.CircularDependency):
print( await loader._async_component_dependencies(hass, "mod_3", mod_3, set(), set())
await loader._async_component_dependencies(
hass, "mod_3", mod_3, set(), set()
)
)
# Depend on non-existing component # Depend on non-existing component
mod_1 = mock_integration(hass, MockModule("mod1", ["nonexisting"])) mod_1 = mock_integration(hass, MockModule("mod1", ["nonexisting"]))
with pytest.raises(loader.IntegrationNotFound): with pytest.raises(loader.IntegrationNotFound):
print( await loader._async_component_dependencies(hass, "mod_1", mod_1, set(), set())
await loader._async_component_dependencies(
hass, "mod_1", mod_1, set(), set()
)
)
# Having an after dependency 2 deps down that is circular # Having an after dependency 2 deps down that is circular
mod_1 = mock_integration( mod_1 = mock_integration(
@ -46,11 +38,7 @@ async def test_component_dependencies(hass):
) )
with pytest.raises(loader.CircularDependency): with pytest.raises(loader.CircularDependency):
print( await loader._async_component_dependencies(hass, "mod_3", mod_3, set(), set())
await loader._async_component_dependencies(
hass, "mod_3", mod_3, set(), set()
)
)
def test_component_loader(hass): def test_component_loader(hass):