Skip to content

Commit 82453b3

Browse files
authored
Merge pull request #43 from flask-extensions/typing
Adds typing
2 parents a16ec04 + 8e3be54 commit 82453b3

File tree

11 files changed

+237
-64
lines changed

11 files changed

+237
-64
lines changed

.github/workflows/tests.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,14 @@ jobs:
2121
- name: Install uv
2222
uses: astral-sh/setup-uv@v6
2323

24+
- name: Run linter
25+
run: uv run ruff check .
26+
27+
- name: Run format
28+
run: uv run ruff format . --check
29+
30+
- name: Run type check
31+
run: uv run mypy .
32+
2433
- name: Run tests
2534
run: uv run pytest

CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ To run tests with all supported Python versions:
1616
$ uv run tox
1717
```
1818

19+
## Linter, format & type check
20+
21+
```console
22+
$ uv run ruff check . --fix
23+
$ uv run ruff format .
24+
$ uv run mypy .
25+
```
26+
1927
## Docs
2028

2129
To build the docs, use [Sphinx](https://www.sphinx-doc.org/en/):

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# -- Project information -----------------------------------------------------
2020

2121
project = "Flask Simple Login"
22-
copyright = "2020, Maely Brandão"
22+
copyright = "2020, Maely Brandão" # noqa: A001
2323
author = "Maely Brandão"
2424

2525

@@ -66,4 +66,4 @@
6666
# Add any paths that contain custom static files (such as style sheets) here,
6767
# relative to this directory. They are copied after the builtin static files,
6868
# so a file named "default.css" will overwrite the builtin "default.css".
69-
html_static_path = []
69+
html_static_path: list[str] = []

example/manage.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,22 @@
44

55
import click
66
from flask import Flask, jsonify, render_template
7-
from flask_simplelogin import Message, SimpleLogin, login_required
87
from werkzeug.security import check_password_hash, generate_password_hash
98

9+
from flask_simplelogin import Message, SimpleLogin, login_required
1010

1111
# [ -- Utils -- ]
1212

1313

1414
def validate_login(user):
15-
db_users = json.load(open("users.json"))
15+
with open("users.json") as handler:
16+
db_users = json.load(handler)
17+
1618
if not db_users.get(user["username"]):
1719
return False
20+
1821
stored_password = db_users[user["username"]]["password"]
19-
if check_password_hash(stored_password, user["password"]):
20-
return True
21-
return False
22+
return check_password_hash(stored_password, user["password"])
2223

2324

2425
def create_user(**data):
@@ -33,11 +34,16 @@ def create_user(**data):
3334

3435
# Here you insert the `data` in your users database
3536
# for this simple example we are recording in a json file
36-
db_users = json.load(open("users.json"))
37+
with open("users.json") as handler:
38+
db_users = json.load(handler)
39+
3740
# add the new created user to json
3841
db_users[data["username"]] = data
42+
3943
# commit changes to database
40-
json.dump(db_users, open("users.json", "w"))
44+
with open("users.json", "w") as handler:
45+
json.dump(db_users, handler)
46+
4147
return data
4248

4349

example/simple_app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from flask import Flask, jsonify, render_template
22
from flask.views import MethodView
3+
34
from flask_simplelogin import SimpleLogin, get_username, login_required
45

56
my_users = {

0 commit comments

Comments
 (0)