The module name overrides the built-in

I am making a game in Python, and it makes sense to have one of my modules named "map". My preferred import method is to do this:

from mygame import map 

As pylint tells me, this overrides the inline. What is the general way to deal with this? Here are the options I can come up with:

1) Ignore the pylint warning, since I still don’t use the built-in card.

2) Change to:

 import mygame 

then mygame.map is indicated in my code.

3) Rename my map module to another (hexmap, gamemap, etc.)

I tend to (2), but I want to see what other people think.

+4
source share
3 answers

This is subjective; there is no right answer.

However, for me 3 is the only reasonable option. Actually really not doing 1; rewriting inline functions is almost never a good idea, in which case it is especially confusing. 2 is better, but I think there is still an expectation that any function called map performs some operation similar to the built-in operation.

Maybe mapping ?

+3
source

Quoth PEP 20 :

Explicit is better than implicit.
In the face of ambiguity, give up the temptation to guess.
There should be one - and only one desirable - an easy way to do this.

mygame.map more explicit than map . mygame.board or mygame.terrain less ambiguous than mygame.map . Guessing if the code says __builtins__.map or mygame.map is scary and will be mostly wrong.

+2
source

Options 2 or 3 will work, however, I think it would be most understandable to rename the map so that it could not be confused. This way you can get a brevity that gives a map link instead of mygame.map , but you won't have any scope issues. In addition, I think the map is a few descriptive variable names, so it would be better to give it a more specific name.

+1
source

All Articles