Skip to content

Sweep the tree for everything conditional on python 2.#425

Draft
albu-diku wants to merge 1 commit intonextfrom
retire/PY2-constant-and-conditionals
Draft

Sweep the tree for everything conditional on python 2.#425
albu-diku wants to merge 1 commit intonextfrom
retire/PY2-constant-and-conditionals

Conversation

@albu-diku
Copy link
Contributor

The only thing explicitly left out is the walk relted code in fileio which is rather weedy and being tackled in a separate change.

@albu-diku
Copy link
Contributor Author

Have found everything I can for now - remaining lint failures are pre-existing issues in the code that complaints now because the corresponding are only applied to changed files, which removal of the constant has made true here.

@jonasbardino
Copy link
Contributor

jonasbardino commented Jan 27, 2026

Have found everything I can for now - remaining lint failures are pre-existing issues in the code that complaints now because the corresponding are only applied to changed files, which removal of the constant has made true here.

Thanks, and yes, we can just point to #338 about the lint errors here, like I did in #424 about the corresponding work on cleaning out the listdir, scandir and walk related leftovers. However, we need to sync on what to cover here and there AFAICT.

@jonasbardino jonasbardino added the refactor Non-functional changes to simplify or clean up label Jan 27, 2026
@jonasbardino
Copy link
Contributor

jonasbardino commented Jan 27, 2026

Well, I suppose we could easily just fix the missing self argument in


which is not covered by #338, but I agree that it's not new and probably slipped in before we had the lint action.

************* Module tests.support.wsgisupp
tests/support/wsgisupp.py:81:8: E0211: Method 'close' has no argument (no-method-argument)

@albu-diku
Copy link
Contributor Author

Well, I suppose we could easily just fix the missing self argument in

which is not covered by #338, but I agree that it's not new and probably slipped in before we had the lint action.

************* Module tests.support.wsgisupp
tests/support/wsgisupp.py:81:8: E0211: Method 'close' has no argument (no-method-argument)

I've got a stack of other changes to wsgisupp elsewhere, so I'd prefer to add this fix either there or to fix it alongsside a test that exercises whatever path through the code requires this. :)

@jonasbardino
Copy link
Contributor

Well, I suppose we could easily just fix the missing self argument in

which is not covered by #338, but I agree that it's not new and probably slipped in before we had the lint action.

************* Module tests.support.wsgisupp
tests/support/wsgisupp.py:81:8: E0211: Method 'close' has no argument (no-method-argument)

I've got a stack of other changes to wsgisupp elsewhere, so I'd prefer to add this fix either there or to fix it alongsside a test that exercises whatever path through the code requires this. :)

Fine with me, it was just to point out that not all lint errors here were already registered and covered e.g. by #338 as I initially thought. I'll let you decide if you want to keep track of it in a new wsgisupp branch or make a mock PR like #338.

@jonasbardino jonasbardino force-pushed the retire/PY2-constant-and-conditionals branch from e13d7ec to eb81f25 Compare February 4, 2026 09:32
jonasbardino added a commit that referenced this pull request Feb 4, 2026
…h cause

noisy errors in annotation as e.g. seen in PR #425 .
@jonasbardino jonasbardino force-pushed the retire/PY2-constant-and-conditionals branch from eb81f25 to 3a23c64 Compare February 4, 2026 10:13
The only thing explicitly left out is the walk relted code in fileio
which is rather weedy and being tackled in a separate change.
@jonasbardino jonasbardino force-pushed the retire/PY2-constant-and-conditionals branch from 3a23c64 to d0a3a82 Compare February 4, 2026 10:19
return textual_output


def NativeStringIO(initial_value=''):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have only two modules using NativeStringIO, namely

  • mig/shared/ssh.py (importing from compat.py)
  • mig/server/grid_sftp.py (importing from base.py
    We probably want to either completely eliminate the wrapper in those two cases, or keep the wrapper here in compat.py so that it is completely clear that it only has relevance in compatibility context and can be phased out along with other py2+3 helpers.

MIG_BASE = os.path.realpath(os.path.join(os.path.dirname(__file__), '../..'))
MIG_ENV = os.getenv('MIG_ENV', 'default')

# NOTE: python3 switched strings to use unicode by default in contrast to bytes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll want to preserve a short note about the point of these variables and their use in shared.base to prevent inadvertent future changes.

# to ensure that all rule files are loaded

for ent in scandir(src_path):
for ent in os.scandir(src_path):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are obsolete with the merge of #424

return [os.fsencode(arg) for arg in argv]


def NativeStringIO(initial_value=''):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See note below about NativeStringIO

from mig.shared.base import client_id_dir, force_utf8
from mig.shared.base import client_id_dir, force_utf8, NativeStringIO
from mig.shared.conf import get_resource_exe, get_configuration_object
from mig.shared.compat import NativeStringIO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See note about NativeStringIO above


# NOTE: moved to urllib.parse in python3 and are re-exposed with future.
# Other modules should import helpers from here for consistency.
# TODO: handle the unicode returned by python3 and future versions!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I suppose this is resolved or just works now but it would be nice to either comment about specifically in the PR / commit log or add a regression test for instead of just silently dropping the TODO.

Copy link
Contributor

@jonasbardino jonasbardino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR is still left marked as draft and the changes to scandir calls no longer apply after merging #424, but I've commented inline and will leave it to you to (eventually) update it before it will be considered for merging @albu-diku.

@jonasbardino
Copy link
Contributor

For the record I've adjusted the lint annotation helper to ignore some common expected mypy errors, which we will generally hit unless we add various explicit type annotations in our code base. There's no need to have them show up as loud errors in the changes tab as they did here before the adjustment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Non-functional changes to simplify or clean up

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants