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

Forbid from-import for meaningless names #814

Closed
orsinium opened this issue Sep 20, 2019 · 5 comments · Fixed by #846
Closed

Forbid from-import for meaningless names #814

orsinium opened this issue Sep 20, 2019 · 5 comments · Fixed by #846
Assignees
Labels
Hacktoberfest Hactoberfest fun! help wanted Extra attention is needed level:starter Good for newcomers pr-merged rule request Adding a new rule
Milestone

Comments

@orsinium
Copy link
Collaborator

Rule request

Thesis

Some packages designed to be imported only as module, and functions inside have name that completes module name.

Bad:

from attr import s
from json import load, dumps
from tomlkit import parse
from schemathesis import from_file

Reasoning

When you see datetime(...) in the code, you know that it's from datetime. When you see BaseView in a Django project, you know that it's from Django framework. When you see loads, it can be anything: yaml, toml, json, custom config.

Proposed solution

Consider the next blacklist:

  • load, loads
  • dump, dumps
  • parse
  • PyYAML specific: safe_load, safe_dump, load_all, dump_all, safe_load_all, safe_dump_all
  • one-letter names
  • Anything that starts from from_ or to_
@orsinium orsinium added the rule request Adding a new rule label Sep 20, 2019
@sobolevn sobolevn added Hacktoberfest Hactoberfest fun! help wanted Extra attention is needed level:starter Good for newcomers labels Sep 20, 2019
@sobolevn sobolevn added this to the Version 0.13 milestone Sep 20, 2019
@sobolevn
Copy link
Member

Awesome!

@lensvol
Copy link
Collaborator

lensvol commented Oct 6, 2019

Can I take it?

@sobolevn
Copy link
Member

sobolevn commented Oct 6, 2019

Sure! Thanks a lot!

@lensvol
Copy link
Collaborator

lensvol commented Oct 6, 2019

I assume this new violation goes under "Best practices"?

@sobolevn
Copy link
Member

sobolevn commented Oct 6, 2019

I will say that it is a consistency rule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hacktoberfest Hactoberfest fun! help wanted Extra attention is needed level:starter Good for newcomers pr-merged rule request Adding a new rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants