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

Need Guidance on Custom Pylint Checker for Library Module #2073

Closed
knappador opened this issue May 10, 2018 · 3 comments
Closed

Need Guidance on Custom Pylint Checker for Library Module #2073

knappador opened this issue May 10, 2018 · 3 comments

Comments

@knappador
Copy link

Hello there, I'm developing a library for doing double-entry accounting:
https://github.com/knappador/enron-py

I'm building a ContextManager for proper transaction treatment. While I can find transactions that don't end up in a proper state before leaving scope, this occurs at runtime. I'd like to get a linter in place for static analysis.

Because the warnings will always be tied to a with scope, I would like to write for a scope-based interface if it exists. Is there a preferred class I can implement?

Second, because it's a library, is there a manner of including the lint checker so that pylint can load the customer checker at library import or would I need to guide users to customize their config? Can I ship the custom lint checker with the project?

Source issue knappador/enron-py#6

@PCManticore
Copy link
Contributor

Hey @knappador Thanks for considering pylint for that! I don't quite follow what you try to do though, would you mind sharing some examples, even in pseudocode?
Regarding your question, the custom lint checker can definitely be shipped with the project. You can then use from a pylintrc file that has to be shipped with the project as well, by using the load-plugins option for passing the plugin along.

@knappador
Copy link
Author

The situation where a lint warning needs to be generated will be of the following form:

with Accounting:   # context manager will track instance creation from here
    result = talk_to_database().black_box_stuff()
    de = DoubleEntry(result...) 
    if (result.some_condition):
        Accounting.realize(de)  # this logic path consumes the double entry
    else:
        return False
# at this point at runtime, in the else branch, we end up warning that the DoubleEntry was
# created but not consumed, meaning we may have just created an accounting violation.

I can start analysis whenever context is opened. I'll be looking for certain API calls in all branches that indicate that each DoubleEntry instance is used once and only once inside a context. Otherwise I want to warn that a subtle bug surface has been introduced.

I also need to be aware if a DoubleEntry is consumed without holding any context. This would result in no ability to guarantee thread safety or to properly track the DoubleEntry fate.

@PCManticore
Copy link
Contributor

Sounds good. I don't have specific suggestions but feel free to look at the checkers that we currently have for some inspiration.

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