Skip to content

Commit

Permalink
refactor: type everything [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
null8626 committed Sep 30, 2024
1 parent af238fd commit fae8502
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import python_weather
import asyncio
import os

async def getweather():
async def getweather() -> None:
# declare the client. the measuring unit used defaults to the metric system (celcius, km/h, etc.)
async with python_weather.Client(unit=python_weather.IMPERIAL) as client:
# fetch a weather forecast from a city
Expand Down
10 changes: 5 additions & 5 deletions docs/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ def __init__(self, header_name: str):
self.character_length = len(header_name)
self.rows = []

def append(self, row_contents: str):
def append(self, row_contents: str) -> None:
self.character_length = max(
self.character_length,
max(map(lambda content: len(list(content)), row_contents.splitlines())),
)
self.rows.append(row_contents)

def render(self, text: str):
def render(self, text: str) -> str:
return f'{text}{" " * (self.character_length - len(text))}'


CHANGE_EMOJIS = {'add': chr(129001), 'fix': chr(128998), 'rem': chr(128997)}


def render_lines(rows: List[Row], character: str = '-'):
def render_lines(rows: List[Row], character: str = '-') -> str:
output = f'+{character}'
last_idx = len(rows) - 1

Expand All @@ -38,7 +38,7 @@ def render_lines(rows: List[Row], character: str = '-'):
return output


def render_contents(rows: List[Row], idx: int):
def render_contents(rows: List[Row], idx: int) -> str:
max_row_lines = max(map(lambda row: len(row.rows[idx].splitlines()), rows))
output = ''

Expand All @@ -57,7 +57,7 @@ def render_contents(rows: List[Row], idx: int):
return output[:-1]


def render(rows: List[Row]):
def render(rows: List[Row]) -> str:
output = f'{render_lines(rows)}\n'

for row in rows:
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Example
import asyncio
import os
async def getweather():
async def getweather() -> None:
# declare the client. the measuring unit used defaults to the metric system (celcius, km/h, etc.)
async with python_weather.Client(unit=python_weather.IMPERIAL) as client:
# fetch a weather forecast from a city
Expand Down
4 changes: 2 additions & 2 deletions python_weather/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def unit(self) -> auto:
return self.__unit

@unit.setter
def unit(self, to: _Unit):
def unit(self, to: _Unit) -> None:
"""
Sets the default measuring unit used to display information in this object.
Expand All @@ -64,7 +64,7 @@ def locale(self) -> Locale:
return self.__locale

@locale.setter
def locale(self, to: Locale):
def locale(self, to: Locale) -> None:
"""
Sets the default localization used to display information in this object.
Expand Down
4 changes: 2 additions & 2 deletions python_weather/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ async def get(
await sleep(delay)
delay *= 2

async def close(self):
async def close(self) -> None:
"""Closes the :class:`Client` object. Nothing will happen if the client uses a pre-existing :class:`aiohttp.ClientSession` or if the session is already closed."""

if self.__own_session and not self.__session.closed:
await self.__session.close()

async def __aenter__(self):
async def __aenter__(self) -> 'Client':
return self

async def __aexit__(self, *_, **__):
Expand Down
12 changes: 6 additions & 6 deletions python_weather/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ class HeatIndex(IndexedEnum):
DANGER = None
EXTREME_DANGER = None

def _new(celcius_index: int, true_index: int):
def _new(celcius_index: int, true_index: int) -> 'HeatIndex':
enum = HeatIndex(celcius_index)
enum.index = true_index

return enum

@classmethod
def _missing_(self, celcius_index: int):
def _missing_(self, celcius_index: int) -> 'HeatIndex':
if celcius_index <= 32:
return self.CAUTION
elif celcius_index <= 39:
Expand All @@ -99,14 +99,14 @@ class UltraViolet(BasicEnum, IndexedEnum):
VERY_HIGH = None
EXTREME = None

def _new(index: int):
def _new(index: int) -> 'UltraViolet':
enum = UltraViolet(index)
enum.index = index

return enum

@classmethod
def _missing_(self, index: int):
def _missing_(self, index: int) -> 'UltraViolet':
if index <= 2:
return self.LOW
elif index <= 5:
Expand Down Expand Up @@ -141,7 +141,7 @@ class WindDirection(BasicEnum):
NORTHWEST = 'NW'
NORTH_NORTHWEST = 'NNW'

def _new(value: str, degrees: float):
def _new(value: str, degrees: float) -> 'WindDirection':
enum = WindDirection(value)
enum.__degrees = degrees

Expand Down Expand Up @@ -310,7 +310,7 @@ class Kind(BasicEnum):
THUNDERY_SNOW_SHOWERS = 392

@classmethod
def _missing_(self, value: int):
def _missing_(self, value: int) -> 'Kind':
if value == 248 or value == 260:
return self.FOG
elif value == 263 or value == 353:
Expand Down
8 changes: 4 additions & 4 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
INDENTATION = 2


def is_local(data):
def is_local(data: object) -> bool:
return getattr(data, '__module__', '').startswith('python_weather')


def _test(obj, indent_level):
def _test(obj: object, indent_level: int) -> None:
for name in dir(obj.__class__):
attr = getattr(obj.__class__, name)

Expand Down Expand Up @@ -40,12 +40,12 @@ def _test(obj, indent_level):
_test(data, indent_level + INDENTATION)


def test(obj):
def test(obj: object) -> None:
print(f'{obj!r} -> ')
_test(obj, INDENTATION)


async def getweather():
async def getweather() -> None:
async with python_weather.Client(unit=python_weather.IMPERIAL) as client:
test(await client.get('New York'))

Expand Down

0 comments on commit fae8502

Please sign in to comment.