Ticket #1740 (new enhancement)

Opened 2 years ago

Last modified 2 years ago

Get rid of `from module import ...`

Reported by: seanh Owned by:
Priority: awaiting triage Milestone: ckan-future
Component: ckan Keywords: refactoring
Cc: Repository: ckan
Theme: none

Description

It's really bad to do from module import * and CKAN has a lot of them. I suggest a three-pronged approach:

  1. Don't add any more of them.
  1. When you're programming if you see an easy opportunity to remove one then do so.
  1. At some point we should task someone to go through the code and remove them all (which is what this ticket is for), but this will be a big job and may break things.

We should also get rid of most or all of the from module import foo and from module import foo, bar statements.

I think the right thing to do is just import module and then use module.foo in your code. But if you find yourself doing module.foo.bar then you may have a code smell.

See: http://docs.python.org/dev/howto/doanddont.html

Change History

comment:1 Changed 2 years ago by dread

I agree with getting rid of from module import * and the approach suggested.

However, I really disagree with getting rid of from x import y. In particular we have a strong convention of using this for ckan.model. It is a valuable abbreviation as it is used so much in the logic layer and tests. If someone should accidentally reassign the value of model to something else then I believe it is simple to see what has gone wrong.

Note: See TracTickets for help on using tickets.