From d27d1076ced11d0b61edbde1a772e922fbdd31e4 Mon Sep 17 00:00:00 2001 From: tanshu Date: Fri, 17 Dec 2021 05:43:58 +0530 Subject: [PATCH] Fix: Account creation failed because of missing code. Chore: Some more mypy settings and their fixes. --- brewman/brewman/models/account_base.py | 5 ++-- brewman/brewman/routers/account.py | 10 ++++---- brewman/brewman/routers/employee.py | 4 ++-- .../brewman/routers/employee_attendance.py | 6 ++--- brewman/brewman/routers/incentive.py | 2 +- brewman/brewman/routers/issue.py | 6 ++--- brewman/brewman/routers/journal.py | 4 ++-- brewman/brewman/routers/product.py | 6 ++--- brewman/brewman/routers/reports/__init__.py | 4 ++-- brewman/brewman/routers/reports/ledger.py | 6 ++--- .../brewman/routers/reports/product_ledger.py | 6 ++--- brewman/brewman/routers/reports/reconcile.py | 10 ++++---- brewman/pyproject.toml | 24 ++++++++++++++----- 13 files changed, 53 insertions(+), 40 deletions(-) diff --git a/brewman/brewman/models/account_base.py b/brewman/brewman/models/account_base.py index fbd75ece..831f8db6 100644 --- a/brewman/brewman/models/account_base.py +++ b/brewman/brewman/models/account_base.py @@ -55,17 +55,18 @@ class AccountBase(Base): def __init__( self, - code: int, name: str, type_id: int, is_starred: bool, is_active: bool, is_reconcilable: bool, cost_centre_id: uuid.UUID, + code: Optional[int] = None, id_: Optional[uuid.UUID] = None, is_fixture: bool = False, ) -> None: - self.code = code + if code is not None: + self.code = code self.name = name self.type_id = type_id self.is_starred = is_starred diff --git a/brewman/brewman/routers/account.py b/brewman/brewman/routers/account.py index f3396825..db1b4638 100644 --- a/brewman/brewman/routers/account.py +++ b/brewman/brewman/routers/account.py @@ -127,10 +127,10 @@ async def show_list(user: UserToken = Depends(get_user)) -> List[schemas.Account @router.get("/query", response_model=List[schemas.AccountLink]) async def show_term( q: str, - t: int = None, # AccountType - r: bool = None, # Reconcilable - a: bool = None, # Active - c: int = None, # Count + t: Optional[int] = None, # AccountType + r: Optional[bool] = None, # Reconcilable + a: Optional[bool] = None, # Active + c: Optional[int] = None, # Count current_user: UserToken = Depends(get_user), ) -> List[schemas.AccountLink]: list_: List[schemas.AccountLink] = [] @@ -158,7 +158,7 @@ async def show_term( @router.get("/{id_}/balance", response_model=AccountBalance) async def show_balance( id_: uuid.UUID, - d: str = None, + d: Optional[str] = None, user: UserToken = Depends(get_user), ) -> AccountBalance: date_ = None if d is None or d == "" else datetime.strptime(d, "%d-%b-%Y") diff --git a/brewman/brewman/routers/employee.py b/brewman/brewman/routers/employee.py index f0f8e5dd..b1c1c44c 100644 --- a/brewman/brewman/routers/employee.py +++ b/brewman/brewman/routers/employee.py @@ -1,7 +1,7 @@ import uuid from datetime import datetime -from typing import List +from typing import List, Optional import brewman.schemas.employee as schemas @@ -131,7 +131,7 @@ async def show_list(user: UserToken = Depends(get_user)) -> List[schemas.Employe @router.get("/query", response_model=List[schemas.EmployeeLink]) async def show_term( q: str, - c: int = None, + c: Optional[int] = None, current_user: UserToken = Depends(get_user), ) -> List[schemas.EmployeeLink]: list_: List[schemas.EmployeeLink] = [] diff --git a/brewman/brewman/routers/employee_attendance.py b/brewman/brewman/routers/employee_attendance.py index 2eaf2917..da62df71 100644 --- a/brewman/brewman/routers/employee_attendance.py +++ b/brewman/brewman/routers/employee_attendance.py @@ -1,7 +1,7 @@ import uuid from datetime import date, datetime -from typing import List +from typing import List, Optional import brewman.schemas.employee_attendance as schemas @@ -39,8 +39,8 @@ def show_blank( def employee_attendance_report( id_: uuid.UUID, request: Request, - s: str = None, - f: str = None, + s: Optional[str] = None, + f: Optional[str] = None, user: UserToken = Security(get_user, scopes=["attendance"]), ) -> schemas.EmployeeAttendance: with SessionFuture() as db: diff --git a/brewman/brewman/routers/incentive.py b/brewman/brewman/routers/incentive.py index 55ae93fb..024c76bf 100644 --- a/brewman/brewman/routers/incentive.py +++ b/brewman/brewman/routers/incentive.py @@ -206,7 +206,7 @@ def get_id( @router.get("", response_model=output.Voucher) def show_blank( request: Request, - d: str = None, + d: Optional[str] = None, user: UserToken = Security(get_user, scopes=["incentive"]), ) -> output.Voucher: additional_info = BlankVoucherInfo(date=d or get_date(request.session), type=VoucherType.INCENTIVE) diff --git a/brewman/brewman/routers/issue.py b/brewman/brewman/routers/issue.py index d4139e2d..68829278 100644 --- a/brewman/brewman/routers/issue.py +++ b/brewman/brewman/routers/issue.py @@ -381,9 +381,9 @@ def get_id( @router.get("", response_model=output.Voucher) def show_blank( request: Request, - date: str = None, - source: uuid.UUID = None, - destination: uuid.UUID = None, + date: Optional[str] = None, + source: Optional[uuid.UUID] = None, + destination: Optional[uuid.UUID] = None, user: UserToken = Security(get_user, scopes=["issue"]), ) -> output.Voucher: date_ = date or get_date(request.session) diff --git a/brewman/brewman/routers/journal.py b/brewman/brewman/routers/journal.py index 0f41eaf1..54a39199 100644 --- a/brewman/brewman/routers/journal.py +++ b/brewman/brewman/routers/journal.py @@ -1,7 +1,7 @@ import uuid from datetime import datetime -from typing import List +from typing import List, Optional import brewman.schemas.input as schema_in import brewman.schemas.voucher as output @@ -190,7 +190,7 @@ def get_id( @router.get("", response_model=output.Voucher) def show_blank( request: Request, - a: uuid.UUID = None, + a: Optional[uuid.UUID] = None, user: UserToken = Security(get_user, scopes=["journal"]), ) -> output.Voucher: if request.scope.get("path") == "/api/payment": diff --git a/brewman/brewman/routers/product.py b/brewman/brewman/routers/product.py index 1e6c20dc..276cdae5 100644 --- a/brewman/brewman/routers/product.py +++ b/brewman/brewman/routers/product.py @@ -193,9 +193,9 @@ def show_list(user: UserToken = Depends(get_user)) -> List[schemas.Product]: @router.get("/q-sku", response_model=List[ProductSku]) async def show_term_sku( - q: str = None, # Query - a: bool = None, # Active - p: bool = None, # Is Purchased? + q: Optional[str] = None, # Query + a: Optional[bool] = None, # Active + p: Optional[bool] = None, # Is Purchased? v: Optional[uuid.UUID] = None, # Vendor d: Optional[str] = None, # Date current_user: UserToken = Depends(get_user), diff --git a/brewman/brewman/routers/reports/__init__.py b/brewman/brewman/routers/reports/__init__.py index f13e39cd..f3767712 100644 --- a/brewman/brewman/routers/reports/__init__.py +++ b/brewman/brewman/routers/reports/__init__.py @@ -2,11 +2,11 @@ from datetime import date, datetime from typing import Optional -def report_start_date(s: str = None) -> Optional[date]: +def report_start_date(s: Optional[str] = None) -> Optional[date]: return None if s is None else datetime.strptime(s, "%d-%b-%Y").date() -def report_finish_date(f: str = None) -> Optional[date]: +def report_finish_date(f: Optional[str] = None) -> Optional[date]: return None if f is None else datetime.strptime(f, "%d-%b-%Y").date() diff --git a/brewman/brewman/routers/reports/ledger.py b/brewman/brewman/routers/reports/ledger.py index 0be75076..ffc34615 100644 --- a/brewman/brewman/routers/reports/ledger.py +++ b/brewman/brewman/routers/reports/ledger.py @@ -1,7 +1,7 @@ import datetime import uuid -from typing import List +from typing import List, Optional import brewman.schemas.ledger as schemas @@ -40,8 +40,8 @@ def show_blank( def show_data( id_: uuid.UUID, request: Request, - s: str = None, - f: str = None, + s: Optional[str] = None, + f: Optional[str] = None, user: UserToken = Security(get_user, scopes=["ledger"]), ) -> schemas.Ledger: with SessionFuture() as db: diff --git a/brewman/brewman/routers/reports/product_ledger.py b/brewman/brewman/routers/reports/product_ledger.py index 861e8270..b19f1b41 100644 --- a/brewman/brewman/routers/reports/product_ledger.py +++ b/brewman/brewman/routers/reports/product_ledger.py @@ -2,7 +2,7 @@ import uuid from datetime import date, datetime from decimal import Decimal -from typing import List, Tuple +from typing import List, Optional, Tuple import brewman.schemas.product_ledger as schemas @@ -44,8 +44,8 @@ def show_blank( def show_data( id_: uuid.UUID, request: Request, - s: str = None, - f: str = None, + s: Optional[str] = None, + f: Optional[str] = None, user: UserToken = Security(get_user, scopes=["product-ledger"]), ) -> schemas.ProductLedger: with SessionFuture() as db: diff --git a/brewman/brewman/routers/reports/reconcile.py b/brewman/brewman/routers/reports/reconcile.py index 8ea648be..d820b610 100644 --- a/brewman/brewman/routers/reports/reconcile.py +++ b/brewman/brewman/routers/reports/reconcile.py @@ -1,7 +1,7 @@ import uuid from datetime import date, datetime -from typing import List +from typing import List, Optional import brewman.schemas.reconcile as schemas @@ -40,8 +40,8 @@ def show_blank( def show_data( id_: uuid.UUID, request: Request, - s: str = None, - f: str = None, + s: Optional[str] = None, + f: Optional[str] = None, user: UserToken = Security(get_user, scopes=["reconcile"]), ) -> schemas.Reconcile: with SessionFuture() as db: @@ -152,8 +152,8 @@ def save( id_: uuid.UUID, data: schemas.Reconcile, request: Request, - s: str = None, - f: str = None, + s: Optional[str] = None, + f: Optional[str] = None, user: UserToken = Security(get_user, scopes=["reconcile"]), ) -> schemas.Reconcile: with SessionFuture() as db: diff --git a/brewman/pyproject.toml b/brewman/pyproject.toml index 85ab4754..5c7b2a04 100644 --- a/brewman/pyproject.toml +++ b/brewman/pyproject.toml @@ -7,16 +7,16 @@ authors = ["tanshu "] [tool.poetry.dependencies] python = "^3.8" uvicorn = {extras = ["standard"], version = "^0.15.0"} -fastapi = "^0.70.0" +fastapi = "^0.70.1" python-jose = {extras = ["cryptography"], version = "^3.3.0"} passlib = {extras = ["bcrypt"], version = "^1.7.4"} -psycopg2-binary = "^2.9.1" -SQLAlchemy = {extras = ["mypy"], version = "^1.4.26"} +psycopg2-binary = "^2.9.2" +SQLAlchemy = {extras = ["mypy"], version = "^1.4.28"} python-multipart = "^0.0.5" PyJWT = "^2.3.0" -alembic = "^1.7.4" +alembic = "^1.7.5" itsdangerous = "^2.0.1" -python-dotenv = "^0.19.1" +python-dotenv = "^0.19.2" pydantic = {extras = ["dotenv"], version = "^1.8.2"} starlette = "^0.16.0" @@ -33,10 +33,22 @@ build-backend = "poetry.core.masonry.api" [tool.mypy] +# --strict +disallow_any_generics = true +disallow_subclassing_any = true +disallow_untyped_calls = true +disallow_untyped_defs = true +disallow_incomplete_defs = true +check_untyped_defs = true +disallow_untyped_decorators = true +no_implicit_optional = true +warn_redundant_casts = true +warn_unused_ignores = true warn_return_any = true warn_unused_configs = true +strict_equality = true plugins = ["sqlalchemy.ext.mypy.plugin"] - +# --strict end [tool.isort] profile = "black"