Skip to content
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

Type hinting and code refactoring #6

Merged
merged 32 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a76f7cb
Be more consistant with U as shorthand for Union
Matthieu-LAURENT39 Oct 3, 2023
73c7ac3
Add function overload for _to_path
Matthieu-LAURENT39 Oct 3, 2023
501f44b
Fix type hinting in attachments.py
Matthieu-LAURENT39 Oct 3, 2023
a014534
Proper type hinting for run_blocking
Matthieu-LAURENT39 Oct 3, 2023
8325349
Improve typing in client.py
Matthieu-LAURENT39 Oct 3, 2023
9b17b86
More typing improvements for client.py
Matthieu-LAURENT39 Oct 3, 2023
08db0c5
simplify code in client.py
Matthieu-LAURENT39 Oct 3, 2023
f7e5e01
improve typing in commands.py
Matthieu-LAURENT39 Oct 3, 2023
5357aab
Some code improvement in commands.py
Matthieu-LAURENT39 Oct 3, 2023
6095c8d
Typing improvements in parsers.py
Matthieu-LAURENT39 Oct 3, 2023
aace357
Code improvement in parsers.py
Matthieu-LAURENT39 Oct 3, 2023
e241f6d
Improve type-hinting in exceptions.py
Matthieu-LAURENT39 Oct 3, 2023
394416c
Fix type hinting in check.py
Matthieu-LAURENT39 Oct 3, 2023
6a37f38
Improve type-hinting in help_command.py
Matthieu-LAURENT39 Oct 3, 2023
75e83d9
Code improvement in string_view.py
Matthieu-LAURENT39 Oct 3, 2023
24765a5
Fix type-hinting in context.py
Matthieu-LAURENT39 Oct 3, 2023
63bfebc
Fixi BaseAttachment import
Matthieu-LAURENT39 Oct 3, 2023
f427a21
Code refactoring in __main__.py
Matthieu-LAURENT39 Oct 3, 2023
bca8449
Fix typo
Matthieu-LAURENT39 Oct 3, 2023
bbeb6fd
Use casefold for case-insentive string comparing
Matthieu-LAURENT39 Oct 3, 2023
64a6467
Ignore type issue for importing __version__
Matthieu-LAURENT39 Oct 3, 2023
abed218
some more fixes to client.py
Matthieu-LAURENT39 Oct 3, 2023
ab74d6b
Edit readme about case insensitivity
Matthieu-LAURENT39 Oct 3, 2023
f2bc1c7
Merge remote-tracking branch 'upstream/master'
Matthieu-LAURENT39 Oct 4, 2023
8f1c68a
Fix typing in context.py
Matthieu-LAURENT39 Oct 4, 2023
9236a84
Clean up typing in client.py
Matthieu-LAURENT39 Oct 4, 2023
606bf49
Document and refactor client._get_id
Matthieu-LAURENT39 Oct 4, 2023
fe7d9d8
Remove deprecated typing containers (List / Dict)
Matthieu-LAURENT39 Oct 4, 2023
0717a64
Ignore some errors that make sense
Matthieu-LAURENT39 Oct 4, 2023
dd73de6
Handle str rooms in edit_message
Matthieu-LAURENT39 Oct 4, 2023
c06fdbc
Merge remote-tracking branch 'upstream/master'
Matthieu-LAURENT39 Oct 4, 2023
c28fdb4
Use sphinx-style for docstring instead of numpy
Matthieu-LAURENT39 Oct 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ bot = Bot(
homeserver="https://matrix.org", # your homeserver
user_id="@__example__:matrix.org", # the user ID to log in as (Fully qualified)
command_prefix="!", # the prefix to respond to (case sensitive, must be lowercase if below is True)
case_insensitive=True, # messages will be lower()cased before being handled. This is recommended.
case_insensitive=True, # messages will be casefold()ed before being handled. This is recommended.
owner_id="@owner:homeserver.com" # The user ID who owns this bot. Optional, but required for bot.is_owner(...).
)

Expand Down
2 changes: 1 addition & 1 deletion src/niobot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .utils import *

try:
import __version__ as version_meta
import __version__ as version_meta # type: ignore
except ImportError:

class __VersionMeta:
Expand Down
14 changes: 7 additions & 7 deletions src/niobot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def test_homeserver(homeserver: str):
parsed = urllib.parse.urlparse(homeserver)
if not parsed.scheme:
logger.info("No scheme found, assuming HTTPS.")
parsed = urllib.parse.urlparse("https://" + homeserver)
parsed = urllib.parse.urlparse(f"https://{homeserver}")

if not parsed.netloc:
logger.critical("No netloc found, cannot continue.")
Expand All @@ -205,7 +205,7 @@ def test_homeserver(homeserver: str):
logger.info("Trying well-known of %r...", parsed.netloc)
base_url = None
try:
response = httpx.get("https://%s/.well-known/matrix/client" % parsed.netloc, timeout=30)
response = httpx.get(f"https://{parsed.netloc}/.well-known/matrix/client", timeout=30)
except httpx.HTTPError as e:
logger.critical("Failed to get well-known: %r", e)
return
Expand Down Expand Up @@ -238,13 +238,13 @@ def test_homeserver(homeserver: str):

if not base_url:
logger.info("No well-known found. Assuming %r as homeserver.", parsed.netloc)
base_url = urllib.parse.urlparse("https://" + parsed.netloc)
base_url = urllib.parse.urlparse(f"https://{parsed.netloc}")

base_url = base_url.geturl()
logger.info("Using %r as homeserver.", base_url)
logger.info("Validating homeserver...")
try:
response = httpx.get(base_url + "/_matrix/client/versions", timeout=30)
response = httpx.get(f"{base_url}/_matrix/client/versions", timeout=30)
except httpx.HTTPError as e:
logger.critical("Failed to get versions: %r", e)
return
Expand Down Expand Up @@ -310,7 +310,7 @@ def get_access_token(ctx, username: str, password: str, homeserver: str, device_
status_code = None
try:
response = httpx.post(
homeserver + "/_matrix/client/r0/login",
f"{homeserver}/_matrix/client/r0/login",
json={
"type": "m.login.password",
"identifier": {"type": "m.id.user", "user": username},
Expand All @@ -327,10 +327,10 @@ def get_access_token(ctx, username: str, password: str, homeserver: str, device_
response.raise_for_status()
except httpx.HTTPError as e:
click.secho("Failed!", fg="red", nl=False)
click.secho(" (%s)" % status_code or str(e), bg="red")
click.secho(f" ({status_code or str(e)})", bg="red")
else:
click.secho("OK", fg="green")
click.secho("Access token: %s" % response.json()["access_token"], fg="green")
click.secho(f'Access token: {response.json()["access_token"]}', fg="green")


@cli_root.group()
Expand Down
Loading