Skip to content

Commit

Permalink
Don't re-export imports outside of __init__.py (#2226)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam authored May 28, 2024
1 parent d2ad5e7 commit fe5cd1e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ jobs:
- run: pycln . --config=pycln.toml --check
- uses: chartboost/ruff-action@v1
with:
version: '0.3.4'
version: '0.3.7'
- uses: psf/black@stable
with:
options: "--fast --check --diff --verbose"
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ repos:
args: [--config=pycln.toml]
verbose: true
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.4
rev: v0.3.7
hooks:
- id: ruff # Run the linter.
args: [--fix]
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/scriptutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def CheckFile():


def RunTabNanny(filename):
import io as io
import io

tabnanny = FindTabNanny()
if tabnanny is None:
Expand Down
2 changes: 1 addition & 1 deletion adodbapi/process_connect_string.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
""" a clumsy attempt at a macro language to let the programmer execute code on the server (ex: determine 64bit)"""

from . import is64bit as is64bit
from . import is64bit


def macro_call(macro_name, args, kwargs):
Expand Down
4 changes: 2 additions & 2 deletions com/win32com/client/gencache.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
# Typing as Any because PyITypeLib is not exposed
demandGeneratedTypeLibraries: dict[tuple[str, int, int, int], Any] = {}

import pickle as pickle
import pickle


def __init__():
Expand Down Expand Up @@ -91,7 +91,7 @@ def _SaveDicts():
def _LoadDicts():
# Load the dictionary from a .zip file if that is where we live.
if is_zip:
import io as io
import io

loader = win32com.__loader__
arc_path = loader.archive
Expand Down
20 changes: 14 additions & 6 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
# Target the oldest supported version
target-version = "py37"

[lint]
select = ["I"]
select = [
"I", # isort
"PLC", # Pylint Convention
]

[lint.per-file-ignores]
# Explicit re-exports is fine in __init__.py, still a code smell elsewhere.
"__init__.py" = ["PLC0414"]

[lint.isort]
combine-as-imports = true
# Because pywin32 has a mix of relative and absolute imports, with undetectable first-party c-extensions
# This makes import grouping more consistent
detect-same-package = false
known-third-party = [
"__main__",
# This forces distutils imports to always be after setuptools
# setuptools must be imported before distutils because it monkey-patches it.
# distutils is also removed in Python 3.12 and deprecated with setuptools
"distutils",
"__main__",
# This forces distutils imports to always be after setuptools
# setuptools must be imported before distutils because it monkey-patches it.
# distutils is also removed in Python 3.12 and deprecated with setuptools
"distutils",
]
extra-standard-library = ["setuptools"]
4 changes: 3 additions & 1 deletion win32/winxpgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

import warnings

from win32console import GetConsoleWindow as GetConsoleWindow
from win32console import (
GetConsoleWindow as GetConsoleWindow, # noqa: PLC0414 # Explicit re-export
)
from win32gui import *

warnings.warn(
Expand Down

0 comments on commit fe5cd1e

Please sign in to comment.