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

add type stubs #79

Closed
wants to merge 4 commits into from
Closed

add type stubs #79

wants to merge 4 commits into from

Conversation

cj81499
Copy link
Contributor

@cj81499 cj81499 commented Oct 30, 2022

resolves #78

@codecov
Copy link

codecov bot commented Oct 30, 2022

Codecov Report

Merging #79 (aee0bde) into main (c7fe7d3) will increase coverage by 0.04%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main      #79      +/-   ##
==========================================
+ Coverage   92.53%   92.57%   +0.04%     
==========================================
  Files          24       24              
  Lines        2009     2020      +11     
  Branches      223      264      +41     
==========================================
+ Hits         1859     1870      +11     
  Misses        123      123              
  Partials       27       27              
Impacted Files Coverage Δ
tests/test_models.py 100.00% <0.00%> (ø)
aocd/models.py 90.43% <0.00%> (+0.08%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

"AOC_TZ",
"__version__",
"data",
]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too familiar with .pyi files, but does it mean I now need to maintain this list in 2 different places? That's a little annoying..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, yes.

Aside from types directly in .py files (which is unpleasant when you need Python 2 support, and (afaik) not possible when you're "hacking" sys.modules like aocd/__init__.py does, I don't know of anything better.

- "3.11" # newest supported Python 3
- "pypy-2.7" # PyPy 2
- "pypy-3.7" # oldest supported PyPy 3
- "pypy-3.9" # newest supported PyPy 3

steps:
Copy link
Owner

@wimglenn wimglenn Oct 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super familiar with typing, but can you add something in here which actually uses mypy? So that we are getting some value and "coverage" of the stubs directly in the CI.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be doable.

The .py files in aocd are ignored by mypy because the stubs exist, so perhaps we should check that the tests use the type hints correctly?

I guess the other option would be to use the comment form of type hints directly within the .py files (except for __init__.py, where we can't (or at least, I don't know how to) due to the sys.modules hack), and then we could type check both the library and the tests (although, this'll be a larger change...).

There's also stubtest, although I've never used it. All the other Python I've worked on using types is Python 3.5+, so I can just use the variable_name: type form in .py files (rather than .pyi stubs) so I've just type checked the library and tests directly with mypy.

It's also worth mentioning, mypy has fully dropped support for Python <= 3.5. Maybe we should only type check using Python 3.11 (at least, until you decide to drop support for older Python versions)?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's fine to check only on one Python version & platform - whichever version is most convenient. Checking the tests seems OK, although I wouldn't be surprised if something in the mocking is not exactly type-correct (I am only considering "duck types" at best when writing test code)

@wimglenn
Copy link
Owner

wimglenn commented Jul 15, 2023

@cj81499 Support for Python < 3.9 was dropped in #108. The next release will be aocd 2.0.0, and it will require Python >= 3.9. Stub files are no longer the right approach for adding typing, so I'm going to close this PR, but I'll leave #78 open in case you're interested to annotate in the .py directly.

@wimglenn wimglenn closed this Jul 15, 2023
@cj81499
Copy link
Contributor Author

cj81499 commented Jul 16, 2023

Makes sense to me. I honestly completely forgot I had this half-done 😵‍💫

Any idea when you'll release 2.0.0? Would like to understand if I have any chance of putting up a PR in time for release.

@wimglenn
Copy link
Owner

don’t know - sometime before December 1st

@wimglenn
Copy link
Owner

2.0.0 is released now, but that doesn't mean I won't release any new version(s) before Dec, so don't let it discourage you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Include type information
2 participants