• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kimata / my-py-lib / 21103773975

18 Jan 2026 01:15AM UTC coverage: 63.379% (-0.01%) from 63.39%
21103773975

push

github

kimata
fix: ty check の型警告を修正

- config.py: schema.get() 呼び出し前に isinstance チェックを追加
- webapp/base.py: STATIC_DIR_PATH をローカル変数に代入して型ナローイングを改善

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

1 of 4 new or added lines in 2 files covered. (25.0%)

1 existing line in 1 file now uncovered.

3515 of 5546 relevant lines covered (63.38%)

0.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/my_lib/webapp/base.py
1
#!/usr/bin/env python3
2
from __future__ import annotations
×
3

4
from typing import cast
×
5

6
import flask
×
7

8
import my_lib.flask_util
×
9
import my_lib.webapp.config
×
10

11
blueprint = flask.Blueprint("webapp-base", __name__)
×
12

13

14
def _get_file_path(filename: str) -> str | None:
×
15
    if my_lib.webapp.config.STATIC_DIR_PATH is None:
×
16
        return None
×
17
    static_dir = my_lib.webapp.config.STATIC_DIR_PATH.resolve()
×
18
    requested_path = (static_dir / filename).resolve()
×
19

20
    if not str(requested_path).startswith(str(static_dir)):
×
21
        return None
×
22

23
    return str(requested_path)
×
24

25

26
@blueprint.route("/", defaults={"filename": "index.html"})
×
27
@blueprint.route("/<path:filename>")
×
28
@my_lib.flask_util.file_etag(filename_func=_get_file_path)
×
29
@my_lib.flask_util.gzipped
×
30
def webapp(filename: str) -> flask.Response:
×
31
    try:
×
NEW
32
        static_dir_path = my_lib.webapp.config.STATIC_DIR_PATH
×
NEW
33
        if static_dir_path is None:
×
UNCOV
34
            flask.abort(500)
×
35

NEW
36
        static_dir = static_dir_path.resolve()
×
37
        requested_path = (static_dir / filename).resolve()
×
38

39
        if not str(requested_path).startswith(str(static_dir)):
×
40
            flask.abort(404)
×
41

42
        # NOTE: static_dir は上で STATIC_DIR_PATH が None でないことを確認後に取得しているので
43
        # 型チェッカーが Path 型として認識できる
44
        if requested_path.exists():
×
45
            etag = my_lib.flask_util.calculate_etag(file_path=str(requested_path), weak=True)
×
46

47
            if etag and my_lib.flask_util.check_etag(etag, flask.request.headers):
×
48
                response = flask.make_response("", 304)
×
49
                response.headers["ETag"] = etag
×
50
                response.headers["Cache-Control"] = "max-age=86400, must-revalidate"
×
51
                return response
×
52

53
            response = flask.send_from_directory(static_dir, filename)
×
54

55
            if response.status_code == 200:
×
56
                response.headers["ETag"] = etag
×
57
                response.headers["Cache-Control"] = "max-age=86400, must-revalidate"
×
58

59
            return response
×
60
        else:
61
            return flask.send_from_directory(static_dir, filename)
×
62
    except (ValueError, OSError):
×
63
        flask.abort(404)
×
64

65

66
blueprint_default = flask.Blueprint("webapp-default", __name__)
×
67

68

69
@blueprint_default.route("/")
×
70
@my_lib.flask_util.gzipped
×
71
def root() -> flask.Response:
×
72
    return cast(flask.Response, flask.redirect(f"{my_lib.webapp.config.URL_PREFIX}/"))
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc