From 0624dc87f6c31908b382b84d904f035614a15c5d Mon Sep 17 00:00:00 2001 From: Ashley Whetter Date: Fri, 20 Aug 2021 19:07:05 -0700 Subject: [PATCH] pylint does not crash when PYLINT_HOME does not exist Closes #4883 --- ChangeLog | 4 ++-- pylint/config/__init__.py | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 29228417a2a..5a139835688 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,9 +15,9 @@ What's New in Pylint 2.10.1? ============================ Release date: TBA -.. - Put bug fixes that should not wait for a new minor version here +* pylint does not crash when PYLINT_HOME does not exist. + Closes #4883 What's New in Pylint 2.10.0? diff --git a/pylint/config/__init__.py b/pylint/config/__init__.py index 01c3e671e7b..1b7b142067b 100644 --- a/pylint/config/__init__.py +++ b/pylint/config/__init__.py @@ -35,6 +35,7 @@ # For details: https://github.com/PyCQA/pylint/blob/main/LICENSE import os +import pathlib import pickle import sys from datetime import datetime @@ -86,12 +87,14 @@ file=sys.stderr, ) # Remove old spam prevention file - for filename in os.listdir(PYLINT_HOME): - if prefix_spam_prevention in filename: - try: - os.remove(os.path.join(PYLINT_HOME, filename)) - except OSError: - pass + if os.path.exists(PYLINT_HOME): + for filename in os.listdir(PYLINT_HOME): + if prefix_spam_prevention in filename: + try: + os.remove(os.path.join(PYLINT_HOME, filename)) + except OSError: + pass + # Create spam prevention file for today try: with open(spam_prevention_file, "w", encoding="utf8") as f: