5

I am formatting Python code using pylint and getting some unwanted warning messages which are given below.

C:204, 0: Invalid function name "sendPasswordViaEmail" (invalid-name)
C:207, 4: Invalid variable name "to" (invalid-name)
W:213, 4: Statement seems to have no effect (pointless-statement)

I am providing my code related to the above messages below.

if request.method == 'POST':
        name = request.POST.get('uname')
        email = request.POST.get('uemail')
        range_start = 10 ** (4 - 1)
        range_end = (10 ** 4) - 1
        password = randint(range_start, range_end)
        passw = User(
            uname=name,
            password=password,
            raw_password=password,
        )
        passw.save()
        sendPasswordViaEmail(str(password), email)
    return render(request, 'bookingservice/login.html')


def sendPasswordViaEmail(password, email):
    """ Send email to user"""

    to = email
    gmail_user = settings.EMAIL
    gmail_pwd = settings.PASSWORD
    smtpserver = smtplib.SMTP("smtp.gmail.com", 587)
    smtpserver.ehlo()
    smtpserver.starttls()
    smtpserver.ehlo
    smtpserver.login(gmail_user, gmail_pwd)
    header = 'To:' + to + '\n' + 'From: ' + \
        gmail_user + '\n' + 'Subject:password \n'
    msg = header + '\n Your password is\n\n' + password
    smtpserver.sendmail(gmail_user, to, msg)
    smtpserver.close()
3
  • That's a PyLint message. "Used when a name doesn't doesn't fit the naming convention associated to its type (constant, variable, class…)". Commented Aug 8, 2017 at 6:02
  • Check this up: stackoverflow.com/a/25184336/2955375 Commented Aug 8, 2017 at 6:02
  • sendPasswordViaEmail is an invalid name. Right name is send_password_via_email Commented Aug 8, 2017 at 6:04

1 Answer 1

11

These messages are warnings (your code works), not errors.

sendPasswordViaEmail is a camel case name. Functions should be "snake case". Rename it send_password_via_email.

to is too short. Try recipient or something else meaningful in place.

The line containing smtpserver.ehlo whithout parentheses does nothing and is thus useless.

Sign up to request clarification or add additional context in comments.

1 Comment

That last one is weird. Does pylint really check that you aren't accessing a descriptor with side effects?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.