Skip to content

fix: replace bare except with except Exception (3 files)#18484

Open
harshadkhetpal wants to merge 3 commits intopytorch:mainfrom
harshadkhetpal:fix/bare-except-pytree
Open

fix: replace bare except with except Exception (3 files)#18484
harshadkhetpal wants to merge 3 commits intopytorch:mainfrom
harshadkhetpal:fix/bare-except-pytree

Conversation

@harshadkhetpal
Copy link
Copy Markdown

@harshadkhetpal harshadkhetpal commented Mar 25, 2026

Summary

Replace bare except: clauses with except Exception: across 3 files to improve error handling specificity.

Bare except: catches all exceptions including SystemExit, KeyboardInterrupt, and GeneratorExit, which should typically propagate. Since none of these sites re-raise, except Exception: is the correct replacement (PEP 8, B001).

Changes:

extension/pytree/__init__.py:

# Before
except:
# After
except Exception:

examples/models/mobilenet_v2/model.py:

# Before
            except:
# After
            except Exception:

examples/models/llama/install_requirement_helper.py (2 occurrences):

# Before
    except:
    except:
# After
    except Exception:
    except Exception:

Testing

No behavior change — style/correctness fix only. All sites are import fallbacks or error-swallowing patterns where Exception is the appropriate base class.

cc @mergennachin @iseeyuan @lucylq @helunwencser @tarun292 @kimishpatel @jackzhxng @larryliu0820 @cccclai

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot bot commented Mar 25, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/18484

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 Awaiting Approval, 1 New Failure, 3 Unrelated Failures

As of commit 09a9209 with merge base b9a6b84 (image):

AWAITING APPROVAL - The following workflow needs approval before CI can run:

NEW FAILURE - The following job has failed:

  • Lint / lintrunner-mypy (gh)
    >>> Lint for backends/arm/test/models/stable_diffusion/stable_diffusion_module_test_configs.py:

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla
Copy link
Copy Markdown

meta-cla bot commented Mar 25, 2026

Hi @harshadkhetpal!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@nil-is-all nil-is-all added the module: examples Issues related to demos under examples/ label Mar 25, 2026
@github-actions
Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@nil-is-all
Copy link
Copy Markdown
Contributor

Hi @harshadkhetpal, do resolve the errors logged by the lintrunner and let us know.

@nil-is-all nil-is-all added module: llm Issues related to LLM examples and apps, and to the extensions/llm/ code and removed module: examples Issues related to demos under examples/ labels Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: llm Issues related to LLM examples and apps, and to the extensions/llm/ code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants