Skip to content

Commit 337393d

Browse files
committed
Allowing OswExpress to be constructed without the positional arg 'domain' if set in defaults
1 parent 6d72419 commit 337393d

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎src/osw/express.py‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
import re
88
from io import TextIOWrapper
99
from pathlib import Path
10+
from typing import overload
1011
from uuid import uuid4
1112
from warnings import warn
1213

1314
from typing_extensions import (
1415
IO,
15-
TYPE_CHECKING,
1616
Any,
1717
AnyStr,
1818
Buffer,
@@ -64,12 +64,30 @@ class OswExpress(OSW):
6464
class Config:
6565
arbitrary_types_allowed = True
6666

67+
@overload
6768
def __init__(
6869
self,
6970
domain: str,
7071
cred_filepath: Union[str, Path] = None,
7172
cred_mngr: CredentialManager = None,
73+
) -> None: ...
74+
75+
def __init__(
76+
self,
77+
domain: str = None,
78+
cred_filepath: Union[str, Path] = None,
79+
cred_mngr: CredentialManager = None,
7280
):
81+
if domain is None:
82+
if default_params.has_changed("wiki_domain"):
83+
domain = default_params.wiki_domain
84+
else:
85+
raise TypeError(
86+
"The constructor of OswExpress is missing 1 required positional argument: 'domain'." # noqa: E501
87+
"\nIf no domain was set via "
88+
"osw.defaults.params.wiki_domain = <domain>, "
89+
"'domain' is a required argument."
90+
)
7391
if cred_filepath is None:
7492
# Set default
7593
cred_filepath = default_paths.cred_filepath

‎tests/integration/test_express.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def test_init_with_defaults_set(wiki_domain, wiki_username, wiki_password):
112112
# This import will trigger the install_dependencies method call on the first run
113113
import osw.express
114114

115-
osw_express = osw.express.OswExpress(domain=wiki_domain)
115+
osw_express = osw.express.OswExpress()
116116
osw_express_and_credentials(osw_express, wiki_domain, wiki_username, wiki_password)
117117
assert osw_express.cred_filepath == Path(cred_filepath)
118118
osw_express.shut_down()

0 commit comments

Comments
 (0)