Skip to content

Commit 23f44e1

Browse files
authored
Merge pull request #83 from chennes/cleanupEmptyExcepts
Add comments to empty except clauses
2 parents 4bf09e7 + 28f486e commit 23f44e1

9 files changed

+15
-14
lines changed

Addon.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ def enable(self):
669669
try:
670670
os.unlink(stopfile)
671671
except FileNotFoundError:
672+
# If the file disappeared on us, there's no need to do anything, it's gone already
672673
pass
673674

674675
if self.contains_workbench():
@@ -771,6 +772,7 @@ def _find_classname_in_file(current_file) -> str:
771772
if search_result:
772773
return search_result.group(1)
773774
except OSError:
775+
# Fall through to the classname-not-found case (if we couldn't read the file, etc.)
774776
pass
775777
return ""
776778

AddonManagerTest/app/test_utilities.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ class TestUtilities(unittest.TestCase):
4343

4444
@classmethod
4545
def tearDownClass(cls):
46-
try:
46+
if os.path.exists("AM_INSTALLATION_DIGEST.txt"):
4747
os.remove("AM_INSTALLATION_DIGEST.txt")
48-
except FileNotFoundError:
49-
pass
5048

5149
def test_recognized_git_location(self):
5250
recognized_urls = [

NetworkManager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ def __setup_network_request(self):
292292
self.monitored_connections.append(item.index)
293293
self.__launch_request(item.index, item.request)
294294
except queue.Empty:
295+
# Once the queue is empty, there's nothing left to do for now
295296
pass
296297

297298
def __launch_request(self, index: int, request: QtNetwork.QNetworkRequest) -> None:

addonmanager_dependency_installer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ def run(self):
8787
if not QtCore.QThread.currentThread().isInterruptionRequested():
8888
self._install_addons()
8989
self.finished_successfully = self.required_succeeded
90-
except RuntimeError:
91-
pass
90+
except RuntimeError as e:
91+
fci.Console.PrintError(str(e) + "\n")
9292
self.finished.emit(self.finished_successfully)
9393

9494
def _install_python_packages(self):

addonmanager_freecad_interface.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,8 @@ def __del__(self):
266266
if not FreeCAD and self.reference_count <= 0:
267267
paths = [self.data_dir, self.mod_dir, self.cache_dir, self.macro_dir, self.mod_dir]
268268
for path in paths:
269-
try:
269+
if os.path.isdir(path):
270270
os.rmdir(path)
271-
except FileNotFoundError:
272-
pass
273271
self.data_dir = None
274272
self.mod_dir = None
275273
self.cache_dir = None

addonmanager_git.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,5 +476,7 @@ def initialize_git() -> Optional[GitManager]:
476476
try:
477477
git_manager = GitManager()
478478
except NoGitFound:
479+
# If git wasn't found, we call just fall through to returning the None that is already
480+
# assigned to git_manager
479481
pass
480482
return git_manager

addonmanager_installer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ def run(self, install_method: InstallationMethod = InstallationMethod.ANY) -> bo
164164
):
165165
self.addon_to_install.enable_workbench()
166166
except utils.ProcessInterrupted:
167+
# This isn't really an "exception" per se, it's that the user cancelled the operation,
168+
# so internally we just act like nothing bad happened, but still return false (as in,
169+
# the addon was not installed).
167170
pass
168171
except Exception as e:
169172
fci.Console.PrintLog(str(e) + "\n")

addonmanager_utilities.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,8 @@ def blocking_get(url: str, method=None) -> bytes:
444444
NetworkManager.InitializeNetworkManager()
445445
p = NetworkManager.AM_NETWORK_MANAGER.blocking_get(url, 10000) # 10 second timeout
446446
if p:
447-
try:
447+
if hasattr(p, "data"):
448448
p = p.data()
449-
except AttributeError:
450-
pass
451449
elif requests and method is None or method == "requests":
452450
response = requests.get(url)
453451
if response.status_code == 200:
@@ -564,11 +562,9 @@ def remove_options_and_arg(call_args: List[str], deny_args: List[str]) -> List[s
564562
as --target and --path. We then have to remove e.g. target --path and
565563
its argument, if present."""
566564
for deny_arg in deny_args:
567-
try:
565+
if deny_arg in call_args:
568566
index = call_args.index(deny_arg)
569567
del call_args[index : index + 2] # The option and its argument
570-
except ValueError:
571-
pass
572568
return call_args
573569

574570

addonmanager_workers_startup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,7 @@ def update_and_advance(self, repo: Optional[Addon]) -> None:
863863
)
864864
worker.start()
865865
except queue.Empty:
866+
# If the queue is empty it's not actually an error, it's an expected end condition
866867
pass
867868

868869
def terminate(self, worker) -> None:

0 commit comments

Comments
 (0)