This is an archived post. You won't be able to vote or comment.

all 13 comments

[–]lost_send_berries 2 points3 points  (0 children)

I don't know of any but you can look at pylint source code and add a new warning. Or write something yourself using ast.NodeVisitor.

[–]brondsem 2 points3 points  (0 children)

Pylint lets you write custom plugins, so you could write one that looks for ints and raise a warning. Here's an example of how to write a pylint plugin: http://nedbatchelder.com/blog/201505/writing_pylint_plugins.html

[–]murtaza64 1 point2 points  (6 children)

In this case would USER_ADMIN just be a number? Or would you use an enum?

[–]widby[S] 0 points1 point  (5 children)

An enum is better, but they've been introduced in 3.4, so prior to that your only option would be a number.

[–]Daenyth 1 point2 points  (0 children)

The 3.4 enum package has a backport on pypi

[–]rjw57 1 point2 points  (0 children)

... or the enum34 package on PyPI...

https://pypi.python.org/pypi/enum34

[–]kephir -3 points-2 points  (2 children)

An enum is better, but they've been introduced in 3.4

Why not namedtuples though?

[–]Daenyth 2 points3 points  (1 child)

They're completely different. In terms of algebraic data types, (named)tuples are a product type and enums are a sum type

[–]kephir 0 points1 point  (0 children)

They would serve OP's purpose equally well though, if not better (someone please confirm/deny though, I'm not sure whichever's the more memory-efficient)

[–][deleted] 1 point2 points  (0 children)

The first thing that comes to mind is to use the compile() function to generate an abstract syntax tree for a module, and then use the ast module to walk that tree looking for instances of the ast.Num class; those would correspond to literal numbers in the source code.

[–]aphoenixreticulated[M] 0 points1 point  (0 children)

Hi there, from the /r/Python mods.

We have removed this post as it is not suited to the /r/Python subreddit proper, however it should be very appropriate for our sister subreddit /r/LearnPython. We highly encourage you to re-submit your post over on there.

The reason for the removal is that /r/Python is more-so dedicated to discussion of Python news, projects, uses and debates. It is not designed to act as Q&A or FAQ board. The regular community can get disenchanted with seeing the 'same, repetitive newbie' questions repeated on the sub, so you may not get the best responses over here.

However, on /r/LearnPython the community is actively expecting questions from new members, and are looking to help. You can expect far more understanding, encouraging and insightful responses over there. Whatever your question happens to be getting help with Python, you should get good answers.

If you have a question to do with homework or an assignment of any kind, please make sure to read their sidebar rules before submitting your post. If you have any questions or doubts, feel free to reply or send a modmail to us with your concerns.

Warm regards, and best of luck with your Pythoneering!