-
Notifications
You must be signed in to change notification settings - Fork 28
Add types to infobase db/server modules #277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |||||||||||||
| import datetime | ||||||||||||||
| import logging | ||||||||||||||
| import time | ||||||||||||||
| from typing import TYPE_CHECKING, cast | ||||||||||||||
|
|
||||||||||||||
| import web | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -12,7 +13,10 @@ | |||||||||||||
| from infogami.infobase._dbstore.indexer import Indexer | ||||||||||||||
| from infogami.infobase._dbstore.read import RecentChanges, get_bot_users | ||||||||||||||
| from infogami.infobase._dbstore.save import PropertyManager, SaveImpl | ||||||||||||||
| from infogami.infobase._dbstore.schema import Schema # noqa: F401 | ||||||||||||||
| from infogami.infobase._dbstore.schema import Schema | ||||||||||||||
|
|
||||||||||||||
| if TYPE_CHECKING: | ||||||||||||||
| from infogami.infobase.cache import Cache | ||||||||||||||
|
|
||||||||||||||
| default_schema = None | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -25,21 +29,21 @@ def process_json(key, json_data): | |||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| class DBSiteStore(common.SiteStore): | ||||||||||||||
| def __init__(self, db, schema): | ||||||||||||||
| def __init__(self, db: web.DB, schema: Schema): | ||||||||||||||
| self.db = db | ||||||||||||||
| self.schema = schema | ||||||||||||||
| self.sitename = None | ||||||||||||||
| self.indexer = Indexer() | ||||||||||||||
| self.store = store.Store(self.db) | ||||||||||||||
| self.seq = sequence.SequenceImpl(self.db) | ||||||||||||||
|
|
||||||||||||||
| self.cache = None | ||||||||||||||
| self.cache: "Cache | None" = None | ||||||||||||||
| self.property_manager = PropertyManager(self.db) | ||||||||||||||
|
|
||||||||||||||
| def get_store(self): | ||||||||||||||
| return self.store | ||||||||||||||
|
|
||||||||||||||
| def set_cache(self, cache): | ||||||||||||||
| def set_cache(self, cache: "Cache"): | ||||||||||||||
| self.cache = cache | ||||||||||||||
|
Comment on lines
+32
to
47
|
||||||||||||||
|
|
||||||||||||||
| def get_metadata(self, key, for_update=False): | ||||||||||||||
|
|
@@ -657,9 +661,9 @@ class DBStore(common.Store): | |||||||||||||
| It always returns a the same site irrespective of the sitename. | ||||||||||||||
| """ | ||||||||||||||
|
|
||||||||||||||
| def __init__(self, schema): | ||||||||||||||
| def __init__(self, schema: Schema): | ||||||||||||||
| self.schema = schema | ||||||||||||||
| self.sitestore = None | ||||||||||||||
| self.sitestore: DBSiteStore | None = None | ||||||||||||||
| self.db = create_database(**web.config.db_parameters) | ||||||||||||||
|
|
||||||||||||||
| def has_initialized(self): | ||||||||||||||
|
|
@@ -669,7 +673,7 @@ def has_initialized(self): | |||||||||||||
| except Exception: | ||||||||||||||
| return False | ||||||||||||||
|
|
||||||||||||||
| def create(self, sitename): | ||||||||||||||
| def create(self, sitename: str) -> DBSiteStore: | ||||||||||||||
| if self.sitestore is None: | ||||||||||||||
| self.sitestore = DBSiteStore(self.db, self.schema) | ||||||||||||||
| if not self.has_initialized(): | ||||||||||||||
|
|
@@ -678,7 +682,7 @@ def create(self, sitename): | |||||||||||||
| self.sitestore.initialize() | ||||||||||||||
| return self.sitestore | ||||||||||||||
|
Comment on lines
682
to
683
|
||||||||||||||
| self.sitestore.initialize() | |
| return self.sitestore | |
| sitestore = self.sitestore | |
| assert sitestore is not None | |
| sitestore.initialize() | |
| return sitestore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Connection.set_auth_tokenonly acceptsstr, butself.auth_tokenis initialized toNoneand several call sites pass values that can beNone(e.g. cookie lookups). For consistency and to avoid mypy mismatches, the parameter type should allowNone(e.g.str | None) or the method should defensively normalize/raise when passedNone.