Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Massive unused/unnecessary variable sweep-up, and more #3021

Merged
merged 5 commits into from
Nov 19, 2019

Conversation

ferdnyc
Copy link
Contributor

@ferdnyc ferdnyc commented Sep 27, 2019

As the branch name indicates, this started as just a set of fixes for one specific issue: the throwaway half of the tuple returned by QFileDialog.getOpenFileName(). But, it ballooned into a lot more. All of the changes are centered around the theme of reducing unused-and-unnecessary variables (both to quiet warnings from static analysis, and to streamline the code).

Fix QFileDialog.getOpenFileName() calls

  • Ignore file_type return value, when not used (which is always)
    Apparently the typical pattern for this is:
    filename, _ = QFileDialog.getOpenFileName(...)
    But we can't use that, because we've bound _ to the translation wrapper. So, I just went with:
    filename = QFileDialog.getOpenFileName(...)[0]
  • simplify some logic around empty return values (canceled dialogs)
  • Create fewer variables we don't need/use

Similar cleanup with the use of os.path standard library functions

  • I went through EVERY .py file in the repo, and looked at all of the uses of the os.path library functions, looking to reduce the number of one-sided os.path.split() / os.path.splitext() calls and the unused variables they engendered. Meaning...

    # If x or y is unused in:
    (x, y) = os.path.split(f)
    # then replace it with whichever is appropriate of:
    x = os.path.dirname(f)
    y = os.path.basename(f)
    
    # If m or n is unused in:
    (m, n) = os.path.splitext(f)
    # then replace it with whichever is appropriate of:
    m = os.path.splitext(f)[0]
    n = os.path.splitext(f)[1]
  • Also, cut down on indentation by reworking some loops like:
    Old...

    for x in y:
        if A:
            ...
            if B:
                do_real_work()

    New...

    for x in y:
        if not A:
            continue
        ...
        if not B:
            continue
        do_real_work()
  • Rewrap some really wide / heavily indented lines

Clean up app vs get_app() usage in main_window.py

  • In functions that call get_app() frequently, make sure we've set app = get_app() at the top, and replace every remaining instance of get_app() with app.
  • In functions where we don't access app/get_app() often, eliminate app and just use get_app() directly.

- simplify some logic around empty return values (canceled)
- Create fewer variables we don't need/use
- if x or y is unused in `(x, y) = os.path.split(f)`, replace
  with `x = os.path.dirname(f)` or `y = os.path.basename(f)`

- if m or n is unused in `(m, n) = os.path.splitext(f)`, replace
  with `m = os.path.splitext(f)[0]` or `n = os.path.splitext(f)[1]`

- Cut down on indentation by reworking some loops like:
  - Old...
    for x in y:
        if A:
            ...
            if B:
                do_real_work()
  - New...
    for x in y:
        if not A:
            continue
        ...
        if not B:
            continue
        do_real_work()

- Rewrap some really wide / heavily indented lines
@jonoomph
Copy link
Member

Looking good! conflicts though

@ferdnyc
Copy link
Contributor Author

ferdnyc commented Nov 19, 2019

Resolved, but the final_cut_pro.py exporter conflict was huge, like70% of the entire file. I just blindly took the PR branch version, I'll check now whether that accidentally lost any changes from develop.

@ferdnyc
Copy link
Contributor Author

ferdnyc commented Nov 19, 2019

Looks fine, and Travis is happy. Crossing my fingers and merging.

@ferdnyc ferdnyc merged commit c9af3a7 into OpenShot:develop Nov 19, 2019
@ferdnyc ferdnyc deleted the pyqt-openfile-fixes branch November 19, 2019 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants