Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@nolar
Copy link
Owner

@nolar nolar commented Nov 5, 2025

A follow-up for the dropping of Python 3.9 as end-of-life:

Only the syntax rewrites, no meaningful changes in this PR.

Partially related to:

@nolar nolar added the refactoring Code cleanup without new features added label Nov 5, 2025
# As publicly exposed: we only promise that it is based on one of the built-in loggable classes.
# Mind that these classes have multi-versioned stubs, so we avoid redefining the protocol ourselves.
Logger = Union[logging.Logger, LoggerAdapter]
Logger: TypeAlias = logging.Logger | LoggerAdapter

Check notice

Code scanning / CodeQL

Unused global variable Note

The global variable 'Logger' is not used.

Copilot Autofix

AI about 2 months ago

To correctly fix the problem, we should add (or augment) a module-level __all__ list that includes "Logger". This will make the intent clear: Logger is a public API of the module for external import, even if it is not used internally in this file. To implement this, insert or update the __all__ list near the top of the file, after the docstring and import statements, and ensure "Logger" is in the exported symbol list.


Suggested changeset 1
kopf/_cogs/helpers/typedefs.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/kopf/_cogs/helpers/typedefs.py b/kopf/_cogs/helpers/typedefs.py
--- a/kopf/_cogs/helpers/typedefs.py
+++ b/kopf/_cogs/helpers/typedefs.py
@@ -12,6 +12,8 @@
 import logging
 from typing import TYPE_CHECKING, Any, TypeAlias
 
+__all__ = ["Logger"]
+
 if TYPE_CHECKING:
     LoggerAdapter: TypeAlias = logging.LoggerAdapter[Any]
 else:
EOF
@@ -12,6 +12,8 @@
import logging
from typing import TYPE_CHECKING, Any, TypeAlias

__all__ = ["Logger"]

if TYPE_CHECKING:
LoggerAdapter: TypeAlias = logging.LoggerAdapter[Any]
else:
Copilot is powered by AI and may make mistakes. Always verify output.
import enum
from collections.abc import Iterable, Iterator, Mapping, MutableMapping
from typing import Any, Callable, Generic, Optional, TypeVar, Union
from typing import Any, Callable, Generic, TypeAlias, TypeVar

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'Generic' is not used.

Copilot Autofix

AI about 2 months ago

To fix the problem, we should remove Generic from the import statement on line 7 in kopf/_cogs/structs/dicts.py. Specifically, only delete Generic from from typing import Any, Callable, Generic, TypeAlias, TypeVar and leave the rest of the import statement as-is, since the other imported types are used elsewhere in the code. This change does not affect functionality, but makes dependencies clearer and code cleaner.

Suggested changeset 1
kopf/_cogs/structs/dicts.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/kopf/_cogs/structs/dicts.py b/kopf/_cogs/structs/dicts.py
--- a/kopf/_cogs/structs/dicts.py
+++ b/kopf/_cogs/structs/dicts.py
@@ -4,7 +4,7 @@
 import collections.abc
 import enum
 from collections.abc import Iterable, Iterator, Mapping, MutableMapping
-from typing import Any, Callable, Generic, TypeAlias, TypeVar
+from typing import Any, Callable, TypeAlias, TypeVar
 
 from kopf._cogs.helpers import thirdparty
 
EOF
@@ -4,7 +4,7 @@
import collections.abc
import enum
from collections.abc import Iterable, Iterator, Mapping, MutableMapping
from typing import Any, Callable, Generic, TypeAlias, TypeVar
from typing import Any, Callable, TypeAlias, TypeVar

from kopf._cogs.helpers import thirdparty

Copilot is powered by AI and may make mistakes. Always verify output.
import logging
from collections.abc import MutableMapping
from typing import TYPE_CHECKING, Any, Optional, TextIO
from typing import TYPE_CHECKING, Any, TextIO

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'TextIO' is not used.

Copilot Autofix

AI about 2 months ago

To fix this problem, the unused TextIO import should be removed from the from typing import TYPE_CHECKING, Any, TextIO statement on line 15 in kopf/_core/actions/loggers.py. The best way to fix it without changing existing functionality is to modify the import so it only imports the names that are actually used (TYPE_CHECKING and Any). This change should be made in place, and no other changes are required.

Suggested changeset 1
kopf/_core/actions/loggers.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/kopf/_core/actions/loggers.py b/kopf/_core/actions/loggers.py
--- a/kopf/_core/actions/loggers.py
+++ b/kopf/_core/actions/loggers.py
@@ -12,7 +12,7 @@
 import enum
 import logging
 from collections.abc import MutableMapping
-from typing import TYPE_CHECKING, Any, TextIO
+from typing import TYPE_CHECKING, Any
 
 # Luckily, we do not mock these ones in tests, so we can import them into our namespace.
 try:
EOF
@@ -12,7 +12,7 @@
import enum
import logging
from collections.abc import MutableMapping
from typing import TYPE_CHECKING, Any, TextIO
from typing import TYPE_CHECKING, Any

# Luckily, we do not mock these ones in tests, so we can import them into our namespace.
try:
Copilot is powered by AI and may make mistakes. Always verify output.
# Filters for old/new values of a field.
# NB: `Any` covers all other values, but we want to highlight that they are specially treated.
ValueFilter = Union[None, Any, MetaFilterToken, callbacks.MetaFilterFn]
ValueFilter: TypeAlias = Any | MetaFilterToken | callbacks.MetaFilterFn | None

Check notice

Code scanning / CodeQL

Unused global variable Note

The global variable 'ValueFilter' is not used.

Copilot Autofix

AI about 2 months ago

To fix the problem, since the variable is unused, either remove the assignment entirely or, if it is intentionally present for documentation purposes, rename it using one of the conventions for unused variables (such as prefixing with unused_). Because its definition has no side effects, deletion of this assignment will not change the functionality. The single best way to fix this is to remove line 23 from kopf/_core/intents/filters.py. No further imports, definitions, or changes are needed.

Suggested changeset 1
kopf/_core/intents/filters.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/kopf/_core/intents/filters.py b/kopf/_core/intents/filters.py
--- a/kopf/_core/intents/filters.py
+++ b/kopf/_core/intents/filters.py
@@ -20,4 +20,3 @@
 
 # Filters for old/new values of a field.
 # NB: `Any` covers all other values, but we want to highlight that they are specially treated.
-ValueFilter: TypeAlias = Any | MetaFilterToken | callbacks.MetaFilterFn | None
EOF
@@ -20,4 +20,3 @@

# Filters for old/new values of a field.
# NB: `Any` covers all other values, but we want to highlight that they are specially treated.
ValueFilter: TypeAlias = Any | MetaFilterToken | callbacks.MetaFilterFn | None
Copilot is powered by AI and may make mistakes. Always verify output.
Mapping, MutableMapping, Sequence
from types import FunctionType, MethodType
from typing import Any, Callable, Generic, Optional, TypeVar, cast
from typing import Any, Callable, Generic, TypeVar, cast

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'Generic' is not used.

Copilot Autofix

AI about 2 months ago

The best way to fix the problem is to remove the unused import of Generic from the import statement on line 20. Specifically, edit the line from typing import Any, Callable, Generic, TypeVar, cast to remove Generic so that only the actually used imports remain. This change should only be applied in the file kopf/_core/intents/registries.py, on line 20. No additional imports or definitions are needed.


Suggested changeset 1
kopf/_core/intents/registries.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/kopf/_core/intents/registries.py b/kopf/_core/intents/registries.py
--- a/kopf/_core/intents/registries.py
+++ b/kopf/_core/intents/registries.py
@@ -17,7 +17,7 @@
 from collections.abc import Collection, Container, Iterable, Iterator, \
                             Mapping, MutableMapping, Sequence
 from types import FunctionType, MethodType
-from typing import Any, Callable, Generic, TypeVar, cast
+from typing import Any, Callable, TypeVar, cast
 
 from kopf._cogs.structs import dicts, ids, references
 from kopf._core.actions import execution
EOF
@@ -17,7 +17,7 @@
from collections.abc import Collection, Container, Iterable, Iterator, \
Mapping, MutableMapping, Sequence
from types import FunctionType, MethodType
from typing import Any, Callable, Generic, TypeVar, cast
from typing import Any, Callable, TypeVar, cast

from kopf._cogs.structs import dicts, ids, references
from kopf._core.actions import execution
Copilot is powered by AI and may make mistakes. Always verify output.
"""
import abc
from typing import Any, Optional
from typing import Any, Protocol, TypeAlias

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'TypeAlias' is not used.

Copilot Autofix

AI about 2 months ago

The best way to fix this problem is to remove the unused import of TypeAlias from line 8, thereby cleaning up the code and its dependencies. This should be done by editing the import statement to remove TypeAlias, retaining only Any and Protocol, which are used elsewhere in the file. No further changes are necessary, as the rest of the code does not depend on TypeAlias.

Suggested changeset 1
kopf/_cogs/helpers/thirdparty.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/kopf/_cogs/helpers/thirdparty.py b/kopf/_cogs/helpers/thirdparty.py
--- a/kopf/_cogs/helpers/thirdparty.py
+++ b/kopf/_cogs/helpers/thirdparty.py
@@ -5,7 +5,7 @@
 or to skip them and make typing/runtime dummies for the rest of the codebase.
 """
 import abc
-from typing import Any, Protocol, TypeAlias
+from typing import Any, Protocol
 
 
 # Since client libraries are optional, support their objects only if they are installed.
EOF
@@ -5,7 +5,7 @@
or to skip them and make typing/runtime dummies for the rest of the codebase.
"""
import abc
from typing import Any, Protocol, TypeAlias
from typing import Any, Protocol


# Since client libraries are optional, support their objects only if they are installed.
Copilot is powered by AI and may make mistakes. Always verify output.
@nolar nolar force-pushed the rewrite-py310 branch 3 times, most recently from 7f85a7a to 583eea1 Compare November 5, 2025 11:51
@nolar nolar force-pushed the rewrite-py310 branch 4 times, most recently from 34710db to 60e5aab Compare November 5, 2025 12:40
@nolar nolar merged commit 62bb3f9 into main Nov 5, 2025
23 checks passed
@nolar nolar deleted the rewrite-py310 branch November 5, 2025 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring Code cleanup without new features added

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants