-
-
Notifications
You must be signed in to change notification settings - Fork 184
Rewrite to Python 3.10 syntax #1191
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
Conversation
| # 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
Show autofix suggestion
Hide autofix suggestion
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.
-
Copy modified lines R15-R16
| @@ -12,6 +12,8 @@ | ||
| import logging | ||
| from typing import TYPE_CHECKING, Any, TypeAlias | ||
|
|
||
| __all__ = ["Logger"] | ||
|
|
||
| if TYPE_CHECKING: | ||
| LoggerAdapter: TypeAlias = logging.LoggerAdapter[Any] | ||
| else: |
| 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
Show autofix suggestion
Hide autofix suggestion
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.
-
Copy modified line R7
| @@ -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 | ||
|
|
| 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
Show autofix suggestion
Hide autofix suggestion
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.
-
Copy modified line R15
| @@ -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: |
| # 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
Show autofix suggestion
Hide autofix suggestion
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.
| @@ -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 |
| 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
Show autofix suggestion
Hide autofix suggestion
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.
-
Copy modified line R20
| @@ -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 |
| """ | ||
| import abc | ||
| from typing import Any, Optional | ||
| from typing import Any, Protocol, TypeAlias |
Check notice
Code scanning / CodeQL
Unused import Note
Show autofix suggestion
Hide autofix suggestion
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.
-
Copy modified line R8
| @@ -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. |
7f85a7a to
583eea1
Compare
Relevant: #1174 Signed-off-by: Sergey Vasilyev <[email protected]>
Signed-off-by: Sergey Vasilyev <[email protected]>
34710db to
60e5aab
Compare
Signed-off-by: Sergey Vasilyev <[email protected]>
Signed-off-by: Sergey Vasilyev <[email protected]>
Signed-off-by: Sergey Vasilyev <[email protected]>
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: