浏览代码

asserts in folder reflex/ not allowed anymore

Lendemor 5 月之前
父节点
当前提交
e692b11e85
共有 2 个文件被更改,包括 5 次插入4 次删除
  1. 2 2
      pyproject.toml
  2. 3 2
      reflex/assets.py

+ 2 - 2
pyproject.toml

@@ -93,13 +93,13 @@ build-backend = "poetry.core.masonry.api"
 [tool.ruff]
 target-version = "py39"
 lint.isort.split-on-trailing-comma = false
-lint.select = ["B", "D", "E", "F", "I", "SIM", "W"]
+lint.select = ["B", "D", "E", "F", "I", "SIM", "W", "S101"]
 lint.ignore = ["B008", "D205", "E501", "F403", "SIM115"]
 lint.pydocstyle.convention = "google"
 
 [tool.ruff.lint.per-file-ignores]
 "__init__.py" = ["F401"]
-"tests/*.py" = ["D100", "D103", "D104", "B018"]
+"tests/*.py" = ["D100", "D103", "D104", "B018", "S101"]
 "reflex/.templates/*.py" = ["D100", "D103", "D104"]
 "*.pyi" = ["D301", "D415", "D417", "D418", "E742"]
 "*/blank.py" = ["I001"]

+ 3 - 2
reflex/assets.py

@@ -46,7 +46,7 @@ def asset(
 
     Raises:
         FileNotFoundError: If the file does not exist.
-        ValueError: If subfolder is provided for local assets.
+        ValueError: If subfolder is provided for local assets or the module is not found.
 
     Returns:
         The relative URL to the asset.
@@ -69,7 +69,8 @@ def asset(
     frame = inspect.stack()[_stack_level]
     calling_file = frame.filename
     module = inspect.getmodule(frame[0])
-    assert module is not None
+    if module is None:
+        raise ValueError(f"Module {frame[0]} not found.")
 
     external = constants.Dirs.EXTERNAL_APP_ASSETS
     src_file_shared = Path(calling_file).parent / path