-
Notifications
You must be signed in to change notification settings - Fork 57
Add type annotations #123
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
Add type annotations #123
Changes from 21 commits
4bb3f90
226ed10
d0300bb
9001f79
42beb06
0be9870
5833326
2cdd669
f79fa36
6ba0c82
d364823
39ea8c1
803c2fc
c782e2f
85e3e8b
eae8d2e
5749296
bea135f
d1dfc65
aca3c5d
840a196
288920f
60dcb44
c61b3e3
a75a223
0cfcfba
b66dc7f
9fc0e29
d15e818
7717874
622e783
fa37a44
766807b
14d4adf
bf9e19a
58198a2
dad87b0
408c14e
2bf5021
0d87e5b
d3ea107
8bd78b0
44e9635
0cc874c
54dcec4
5747886
bd15325
495519e
db4fe6a
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.egg-info | ||
__pycache__/ | ||
.coverage* | ||
dist/ | ||
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,7 +1,7 @@ | ||||||
import sys | ||||||
from typing import TYPE_CHECKING, Union | ||||||
wimglenn marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
from functools import partial | ||||||
|
||||||
from . import _ipykernel | ||||||
from . import cli | ||||||
from . import cookies | ||||||
from . import examples | ||||||
|
@@ -16,8 +16,23 @@ | |||||
from .get import get_day_and_year | ||||||
from .post import submit as _impartial_submit | ||||||
|
||||||
__all__ = [ | ||||||
"exceptions", | ||||||
"models", | ||||||
"AocdError", | ||||||
"get_data", | ||||||
"data", | ||||||
"submit", | ||||||
] | ||||||
cj81499 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
def __getattr__(name): | ||||||
data: str | ||||||
lines: list[str] | ||||||
numbers: Union[list[list[int]], list[int], int] | ||||||
wimglenn marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
if TYPE_CHECKING: | ||||||
submit = _impartial_submit | ||||||
|
||||||
def __getattr__(name): # type: ignore[no-untyped-def] # no idea how to provide meaningful types here | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just use
Suggested change
(make sure to import |
||||||
if name == "data": | ||||||
day, year = get_day_and_year() | ||||||
return get_data(day=day, year=year) | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from typing import TYPE_CHECKING, Literal, Optional, Union | ||
|
||
if TYPE_CHECKING: | ||
import numpy as np | ||
|
||
__all__ = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why give these objects private names and then export them? The types would be useful for consumers of the library too; e.g. some 3rd party library might use: from aocd.types import Answer, Part
def process_answer(answer: Answer, part: Part | None = None, **kwargs: Any) -> None:
"""Process an AOC answer before submitting"""
... and you may want to store some of these types:
Note that the |
||
"_Answer", | ||
"_Part", | ||
"_LoosePart", | ||
] | ||
|
||
_Answer = Optional[Union[str, int, float, complex, "np.number"]] | ||
_Part = Literal["a", "b"] | ||
_LoosePart = Union[_Part, Literal[1, "1", 2, "2"]] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have my reservations about the use of |
Uh oh!
There was an error while loading. Please reload this page.