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 checking #3

Open
jvasile opened this issue Feb 19, 2021 · 3 comments
Open

Add type checking #3

jvasile opened this issue Feb 19, 2021 · 3 comments

Comments

@jvasile
Copy link
Member

jvasile commented Feb 19, 2021

In an ideal world, a codebase that receives inconsistent attention would have a full suite of tests, type checks, and sample files. Tests are time-consuming to write and will have to wait on sample files anyway. But type checks! We can do those. This issue is for making progress on getting the codebase to pass "mypy --strict" and we can do it one bit at a time.

Along the way, that will prompt changes that hopefully get us to a better place with consistency and return values and classes.

@radnonymous
Copy link
Contributor

radnonymous commented Feb 22, 2021

I thought I'd take a stab at this, posting this to make sure I'm on the right track.

~$ mypy /path/to/ots-bookkeeping --strict

yields

ots-bookkeeping/plugins/share_postings.py:54: error: Cannot find implementation or library stub for module named 'beancount'
ots-bookkeeping/plugins/share_postings.py:54: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
ots-bookkeeping/plugins/share_postings.py:55: error: Cannot find implementation or library stub for module named 'beancount.core'
ots-bookkeeping/plugins/share_postings.py:61: error: Cannot find implementation or library stub for module named 'beancount.parser'
ots-bookkeeping/plugins/share_postings.py:62: error: Cannot find implementation or library stub for module named 'beancount.query'
ots-bookkeeping/plugins/share_postings.py:67: error: Function is missing a type annotation
ots-bookkeeping/plugins/share_postings.py:119: error: Incompatible types in assignment (expression has type "Pattern[str]", variable has type "str")
ots-bookkeeping/plugins/share_postings.py:127: error: Need type annotation for 'sharees' (hint: "sharees: List[<type>] = ...")
ots-bookkeeping/plugins/share_postings.py:130: error: "str" has no attribute "finditer"
ots-bookkeeping/plugins/share_postings.py:167: error: Function is missing a type annotation
ots-bookkeeping/plugins/share_postings.py:183: error: Incompatible types in assignment (expression has type "Union[Tuple[Any, ...], List[Any]]", variable has type "List[str]")
ots-bookkeeping/plugins/share_postings.py:193: error: Call to untyped function "get_sharing_info" in typed context
ots-bookkeeping/plugins/share_postings.py:206: error: Call to untyped function "get_sharing_info" in typed context
Found 12 errors in 1 file (checked 2 source files)

I'm making a branch that will deal with these errors.
I'm guessing the first four issues are because I haven't given mypy access to beancount yet, so I'm going to disregard them for the time being.

@jvasile
Copy link
Member Author

jvasile commented Feb 24, 2021

+1 to all of this, yeah.

Those first four might not be because mypy can't find beancount but rather because it can't find type information about beancount. This might be because there is none. In that case, we could add type info to beancount (a big project, but a useful one, and they want the changes upstream) or we could add "#type: ignore" to the "import beancount" line.

@jvasile
Copy link
Member Author

jvasile commented Mar 18, 2021

I have been making some progress on this, and you can take a look at my recent commits to see what this work looks like in practice.

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

No branches or pull requests

2 participants