Skip to content

Commit

Permalink
Merge pull request #8 from eandersons/Fix-TypeError
Browse files Browse the repository at this point in the history
Fix type annotations for Python 3.9
  • Loading branch information
kellya committed May 1, 2023
2 parents c07a52c + 6ace846 commit 2e4854e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion maubot.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
maubot: 0.1.0
id: com.arachnitech.weather
version: "0.4.0"
version: "0.4.1"
license: MIT
modules:
- weather
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "maubot-weather"
version = "0.4.0"
version = "0.4.1"
description = "A maubot bot to get the weather from wttr.in and post to a matrix channel"
authors = ["Alex Kelly <[email protected]>"]
license = "MIT"
Expand Down
18 changes: 10 additions & 8 deletions weather/weather.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""" Maubot to get the weather from wttr.in and post in matrix chat """

from re import IGNORECASE, Match, search, sub
from typing import Type
from typing import Dict, Optional, Type, Union
from urllib.parse import urlencode

from maubot import Plugin, MessageEvent
Expand Down Expand Up @@ -152,7 +152,7 @@ def _language(self) -> str:
location = self._stored_location

if "l:" in location:
match: Match[str] | None = search(
match: Optional["Match[str]"] = search(
r"(\bl: *(?!u:)(\S+))", location, IGNORECASE
)

Expand Down Expand Up @@ -182,7 +182,7 @@ def _location(self, location: str = "") -> str:

def _message(self, content: str) -> str:
message: str = content
location_match: Match[str] | None = search(r'^(.+):', message)
location_match: Optional["Match[str]"] = search(r'^(.+):', message)

if self.config["show_link"]:
message += f"([wttr.in]({self._url()}))"
Expand All @@ -200,8 +200,8 @@ def _message(self, content: str) -> str:

return message

def _options(self) -> dict[str, int | str]:
options: dict[str, int | str] = {}
def _options(self) -> Dict[str, Union[int, str]]:
options: Dict[str, Union[int, str]] = {}

if self._stored_language:
options["lang"] = self._stored_language
Expand All @@ -212,7 +212,7 @@ def _options(self) -> dict[str, int | str]:
return options

def _options_querystring(
self, custom_options: dict[str, int | str] | None = None
self, custom_options: Optional[Dict[str, Union[int, str]]] = None
) -> str:
options = self._options()
options.update(custom_options if custom_options else {})
Expand All @@ -230,7 +230,7 @@ def _units(self) -> str:
location = self._stored_location

if "u:" in location:
match: Match[str] | None = search(
match: Optional["Match[str]"] = search(
r"(\bu: *(?!l:)(\S+))", location, IGNORECASE
)

Expand All @@ -249,7 +249,9 @@ def _units(self) -> str:

return self._stored_units

def _url(self, custom_options: dict[str, int | str] | None = None) -> str:
def _url(
self, custom_options: Optional[Dict[str, Union[int, str]]] = None
) -> str:
querystring = self._options_querystring(custom_options)

return (
Expand Down

0 comments on commit 2e4854e

Please sign in to comment.