-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Use X | Y union syntax in error messages #15102
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reports Add hidden option to force union syntax
omarsilva1
changed the title
Display union items with | on error
Use X | Y union syntax in error messages
Apr 22, 2023
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
for more information, see https://pre-commit.ci
(The close/reopen was so that Black would run and hopefully fix the failing build.) |
Diff from mypy_primer, showing the effect of this PR on open source code: aioredis (https://github.com/aio-libs/aioredis)
- aioredis/connection.py:455: error: Type of variable becomes "Optional[Any]" due to an unfollowed import [no-any-unimported]
+ aioredis/connection.py:455: error: Type of variable becomes "Any | None" due to an unfollowed import [no-any-unimported]
- aioredis/connection.py:933: error: Unsupported right operand type for in ("Union[bytes, memoryview, int]") [operator]
+ aioredis/connection.py:933: error: Unsupported right operand type for in ("bytes | memoryview | int") [operator]
- aioredis/connection.py:934: error: Item "memoryview" of "Union[bytes, memoryview, int]" has no attribute "split" [union-attr]
+ aioredis/connection.py:934: error: Item "memoryview" of "bytes | memoryview | int" has no attribute "split" [union-attr]
- aioredis/connection.py:934: error: Item "int" of "Union[bytes, memoryview, int]" has no attribute "split" [union-attr]
+ aioredis/connection.py:934: error: Item "int" of "bytes | memoryview | int" has no attribute "split" [union-attr]
- aioredis/client.py:4114: error: Incompatible types in assignment (expression has type "dict[Union[bytes, str, memoryview], Optional[Any]]", variable has type "dict[Union[bytes, str, memoryview], Callable[[dict[str, str]], Awaitable[None]]]") [assignment]
+ aioredis/client.py:4114: error: Incompatible types in assignment (expression has type "dict[bytes | str | memoryview, Any | None]", variable has type "dict[bytes | str | memoryview, Callable[[dict[str, str]], Awaitable[None]]]") [assignment]
- aioredis/client.py:4158: error: Argument 1 to "update" of "MutableMapping" has incompatible type "dict[Union[bytes, str, memoryview], Optional[Any]]"; expected "SupportsKeysAndGetItem[Union[bytes, str, memoryview], Callable[[dict[str, str]], Awaitable[None]]]" [arg-type]
+ aioredis/client.py:4158: error: Argument 1 to "update" of "MutableMapping" has incompatible type "dict[bytes | str | memoryview, Any | None]"; expected "SupportsKeysAndGetItem[bytes | str | memoryview, Callable[[dict[str, str]], Awaitable[None]]]" [arg-type]
- aioredis/client.py:4172: error: Incompatible types in assignment (expression has type "dict[Union[bytes, str, memoryview], Callable[[dict[str, str]], Awaitable[None]]]", variable has type "dict[Any, Optional[Any]]") [assignment]
+ aioredis/client.py:4172: error: Incompatible types in assignment (expression has type "dict[bytes | str | memoryview, Callable[[dict[str, str]], Awaitable[None]]]", variable has type "dict[Any, Any | None]") [assignment]
pylox (https://github.com/sco1/pylox)
- pylox/containers/array.py:84: note: def [_T] pop(self, Any, Union[Any, _T], /) -> Union[Any, _T]
+ pylox/containers/array.py:84: note: def [_T] pop(self, Any, Any | _T, /) -> Any | _T
- pylox/interpreter.py:160: error: Incompatible types in assignment (expression has type "Optional[Environment]", variable has type "Environment") [assignment]
+ pylox/interpreter.py:160: error: Incompatible types in assignment (expression has type "Environment | None", variable has type "Environment") [assignment]
- pylox/interpreter.py:235: error: Returning Any from function declared to return "Union[float, bool]" [no-any-return]
+ pylox/interpreter.py:235: error: Returning Any from function declared to return "float | bool" [no-any-return]
- pylox/interpreter.py:266: error: Returning Any from function declared to return "Union[float, str, None]" [no-any-return]
+ pylox/interpreter.py:266: error: Returning Any from function declared to return "float | str | None" [no-any-return]
- pylox/interpreter.py:282: error: Returning Any from function declared to return "Union[float, str, None]" [no-any-return]
+ pylox/interpreter.py:282: error: Returning Any from function declared to return "float | str | None" [no-any-return]
- pylox/interpreter.py:286: error: Returning Any from function declared to return "Union[float, str, None]" [no-any-return]
+ pylox/interpreter.py:286: error: Returning Any from function declared to return "float | str | None" [no-any-return]
- pylox/interpreter.py:292: error: Returning Any from function declared to return "Union[float, str, None]" [no-any-return]
+ pylox/interpreter.py:292: error: Returning Any from function declared to return "float | str | None" [no-any-return]
- pylox/interpreter.py:297: error: Returning Any from function declared to return "Union[float, str, None]" [no-any-return]
+ pylox/interpreter.py:297: error: Returning Any from function declared to return "float | str | None" [no-any-return]
- pylox/interpreter.py:300: error: Returning Any from function declared to return "Union[float, str, None]" [no-any-return]
+ pylox/interpreter.py:300: error: Returning Any from function declared to return "float | str | None" [no-any-return]
- pylox/interpreter.py:303: error: Returning Any from function declared to return "Union[float, str, None]" [no-any-return]
+ pylox/interpreter.py:303: error: Returning Any from function declared to return "float | str | None" [no-any-return]
- pylox/interpreter.py:306: error: Returning Any from function declared to return "Union[float, str, None]" [no-any-return]
+ pylox/interpreter.py:306: error: Returning Any from function declared to return "float | str | None" [no-any-return]
- pylox/interpreter.py:309: error: Returning Any from function declared to return "Union[float, str, None]" [no-any-return]
+ pylox/interpreter.py:309: error: Returning Any from function declared to return "float | str | None" [no-any-return]
- pylox/interpreter.py:312: error: Returning Any from function declared to return "Union[float, str, None]" [no-any-return]
+ pylox/interpreter.py:312: error: Returning Any from function declared to return "float | str | None" [no-any-return]
Auto-Split (https://github.com/Avasam/Auto-Split)
- src/capture_method/__init__.py:87: note: def get(self, CaptureMethodEnum, /) -> Optional[Type[CaptureMethodBase]]
+ src/capture_method/__init__.py:87: note: def get(self, CaptureMethodEnum, /) -> Type[CaptureMethodBase] | None
- src/capture_method/__init__.py:87: note: def [_T] get(self, CaptureMethodEnum, Union[Type[CaptureMethodBase], _T], /) -> Union[Type[CaptureMethodBase], _T]
+ src/capture_method/__init__.py:87: note: def [_T] get(self, CaptureMethodEnum, Type[CaptureMethodBase] | _T, /) -> Type[CaptureMethodBase] | _T
- src/capture_method/__init__.py:87: note: def get(self, CaptureMethodEnum, /) -> Optional[Type[CaptureMethodBase]]
+ src/capture_method/__init__.py:87: note: def get(self, CaptureMethodEnum, /) -> Type[CaptureMethodBase] | None
- src/capture_method/__init__.py:87: note: def [_T] get(self, CaptureMethodEnum, /, default: Union[Type[CaptureMethodBase], _T]) -> Union[Type[CaptureMethodBase], _T]
+ src/capture_method/__init__.py:87: note: def [_T] get(self, CaptureMethodEnum, /, default: Type[CaptureMethodBase] | _T) -> Type[CaptureMethodBase] | _T
poetry (https://github.com/python-poetry/poetry)
- src/poetry/utils/password_manager.py:69: error: Returning Any from function declared to return "Optional[str]" [no-any-return]
+ src/poetry/utils/password_manager.py:69: error: Returning Any from function declared to return "str | None" [no-any-return]
- src/poetry/mixology/version_solver.py:426: error: Returning Any from function declared to return "Optional[str]" [no-any-return]
+ src/poetry/mixology/version_solver.py:426: error: Returning Any from function declared to return "str | None" [no-any-return]
- src/poetry/mixology/version_solver.py:455: error: Returning Any from function declared to return "Optional[str]" [no-any-return]
+ src/poetry/mixology/version_solver.py:455: error: Returning Any from function declared to return "str | None" [no-any-return]
- src/poetry/packages/locker.py:362: error: Returning Any from function declared to return "Union[SupportsDunderLT[Any], SupportsDunderGT[Any]]" [no-any-return]
+ src/poetry/packages/locker.py:362: error: Returning Any from function declared to return "SupportsDunderLT[Any] | SupportsDunderGT[Any]" [no-any-return]
- src/poetry/utils/env.py:1016: error: Argument 1 to "generate_env_name" of "EnvManager" has incompatible type "Optional[str]"; expected "str" [arg-type]
+ src/poetry/utils/env.py:1016: error: Argument 1 to "generate_env_name" of "EnvManager" has incompatible type "str | None"; expected "str" [arg-type]
- src/poetry/puzzle/provider.py:169: error: Returning Any from function declared to return "Union[SupportsDunderLT[Any], SupportsDunderGT[Any]]" [no-any-return]
+ src/poetry/puzzle/provider.py:169: error: Returning Any from function declared to return "SupportsDunderLT[Any] | SupportsDunderGT[Any]" [no-any-return]
- src/poetry/console/commands/show.py:435: error: Returning Any from function declared to return "Union[SupportsDunderLT[Any], SupportsDunderGT[Any]]" [no-any-return]
+ src/poetry/console/commands/show.py:435: error: Returning Any from function declared to return "SupportsDunderLT[Any] | SupportsDunderGT[Any]" [no-any-return]
- src/poetry/console/commands/show.py:484: error: Returning Any from function declared to return "Union[SupportsDunderLT[Any], SupportsDunderGT[Any]]" [no-any-return]
+ src/poetry/console/commands/show.py:484: error: Returning Any from function declared to return "SupportsDunderLT[Any] | SupportsDunderGT[Any]" [no-any-return]
pip (https://github.com/pypa/pip)
- src/pip/_internal/metadata/_json.py:67: error: Item "None" of "Optional[list[Any]]" has no attribute "__iter__" (not iterable) [union-attr]
+ src/pip/_internal/metadata/_json.py:67: error: Item "None" of "list[Any] | None" has no attribute "__iter__" (not iterable) [union-attr]
- src/pip/_internal/metadata/_json.py:70: error: Argument 1 to "sanitise_header" has incompatible type "Optional[Any]"; expected "Union[Header, str]" [arg-type]
+ src/pip/_internal/metadata/_json.py:70: error: Argument 1 to "sanitise_header" has incompatible type "Any | None"; expected "Header | str" [arg-type]
- src/pip/_internal/network/xmlrpc.py:36: error: Argument 3 of "request" is incompatible with supertype "Transport"; supertype defines the argument type as "Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]]" [override]
+ src/pip/_internal/network/xmlrpc.py:36: error: Argument 3 of "request" is incompatible with supertype "Transport"; supertype defines the argument type as "bytes | bytearray | memoryview | array[Any] | mmap | _CData | PickleBuffer" [override]
alerta (https://github.com/alerta/alerta)
- alerta/models/key.py:53: error: Argument "expire_time" to "ApiKey" has incompatible type "Optional[datetime]"; expected "datetime" [arg-type]
+ alerta/models/key.py:53: error: Argument "expire_time" to "ApiKey" has incompatible type "datetime | None"; expected "datetime" [arg-type]
- alerta/models/heartbeat.py:88: error: Argument "create_time" to "Heartbeat" has incompatible type "Optional[datetime]"; expected "datetime" [arg-type]
+ alerta/models/heartbeat.py:88: error: Argument "create_time" to "Heartbeat" has incompatible type "datetime | None"; expected "datetime" [arg-type]
- alerta/tasks.py:23: error: Argument 4 to "process_action" has incompatible type "Optional[int]"; expected "int" [arg-type]
+ alerta/tasks.py:23: error: Argument 4 to "process_action" has incompatible type "int | None"; expected "int" [arg-type]
- alerta/tasks.py:24: error: Argument 3 to "from_action" of "Alert" has incompatible type "Optional[int]"; expected "int" [arg-type]
+ alerta/tasks.py:24: error: Argument 3 to "from_action" of "Alert" has incompatible type "int | None"; expected "int" [arg-type]
- alerta/tasks.py:38: error: Argument 3 to "from_status" of "Alert" has incompatible type "Optional[int]"; expected "int" [arg-type]
+ alerta/tasks.py:38: error: Argument 3 to "from_status" of "Alert" has incompatible type "int | None"; expected "int" [arg-type]
aiohttp (https://github.com/aio-libs/aiohttp)
- aiohttp/helpers.py:771: error: Value of type "Optional[list[tuple[str, str]]]" is not indexable [index]
+ aiohttp/helpers.py:771: error: Value of type "list[tuple[str, str]] | None" is not indexable [index]
jax (https://github.com/google/jax)
- jax/_src/numpy/linalg.py:641: error: Incompatible types in assignment (expression has type "Array", variable has type "Optional[float]") [assignment]
+ jax/_src/numpy/linalg.py:641: error: Incompatible types in assignment (expression has type "Array", variable has type "float | None") [assignment]
steam.py (https://github.com/Gobot1234/steam.py)
- steam/_const.py:114: error: Incompatible default for argument "unpacker" (default has type "Callable[[Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], int], tuple[Any, ...]]", argument has type "Callable[[bytes], tuple[int]]") [assignment]
+ steam/_const.py:114: error: Incompatible default for argument "unpacker" (default has type "Callable[[bytes | bytearray | memoryview | array[Any] | mmap | _CData | PickleBuffer, int], tuple[Any, ...]]", argument has type "Callable[[bytes], tuple[int]]") [assignment]
- steam/id.py:94: error: Incompatible types in assignment (expression has type "int", variable has type "Optional[Type]") [assignment]
+ steam/id.py:94: error: Incompatible types in assignment (expression has type "int", variable has type "Type | None") [assignment]
- steam/id.py:95: error: Incompatible types in assignment (expression has type "int", variable has type "Optional[Universe]") [assignment]
+ steam/id.py:95: error: Incompatible types in assignment (expression has type "int", variable has type "Universe | None") [assignment]
- steam/id.py:98: error: Incompatible types in assignment (expression has type "int", variable has type "Optional[Instance]") [assignment]
+ steam/id.py:98: error: Incompatible types in assignment (expression has type "int", variable has type "Instance | None") [assignment]
- steam/id.py:100: note: Right operand is of type "Optional[Universe]"
+ steam/id.py:100: note: Right operand is of type "Universe | None"
- steam/id.py:100: note: Left operand is of type "Optional[Universe]"
+ steam/id.py:100: note: Left operand is of type "Universe | None"
- steam/id.py:102: note: Right operand is of type "Optional[Type]"
+ steam/id.py:102: note: Right operand is of type "Type | None"
- steam/id.py:102: note: Left operand is of type "Optional[Type]"
+ steam/id.py:102: note: Left operand is of type "Type | None"
- steam/id.py:104: note: Right operand is of type "Optional[Instance]"
+ steam/id.py:104: note: Right operand is of type "Instance | None"
- steam/id.py:104: note: Left operand is of type "Optional[Instance]"
+ steam/id.py:104: note: Left operand is of type "Instance | None"
- steam/id.py:114: note: Left operand is of type "Optional[Universe]"
+ steam/id.py:114: note: Left operand is of type "Universe | None"
- steam/id.py:114: note: Left operand is of type "Optional[Type]"
+ steam/id.py:114: note: Left operand is of type "Type | None"
- steam/id.py:114: note: Left operand is of type "Optional[Instance]"
+ steam/id.py:114: note: Left operand is of type "Instance | None"
- steam/id.py:507: error: Argument "instance" to "ID" has incompatible type "int"; expected "Optional[Instance]" [arg-type]
+ steam/id.py:507: error: Argument "instance" to "ID" has incompatible type "int"; expected "Instance | None" [arg-type]
- steam/id.py:558: error: Argument "universe" to "ID" has incompatible type "int"; expected "Optional[Universe]" [arg-type]
+ steam/id.py:558: error: Argument "universe" to "ID" has incompatible type "int"; expected "Universe | None" [arg-type]
- steam/id.py:558: error: Argument "instance" to "ID" has incompatible type "int"; expected "Optional[Instance]" [arg-type]
+ steam/id.py:558: error: Argument "instance" to "ID" has incompatible type "int"; expected "Instance | None" [arg-type]
- steam/models.py:156: error: Value of type "Optional[Match[str]]" is not indexable [index]
+ steam/models.py:156: error: Value of type "Match[str] | None" is not indexable [index]
- steam/models.py:157: error: Value of type "Optional[Match[str]]" is not indexable [index]
+ steam/models.py:157: error: Value of type "Match[str] | None" is not indexable [index]
- steam/package.py:321: error: Value of type "Optional[Match[str]]" is not indexable [index]
+ steam/package.py:321: error: Value of type "Match[str] | None" is not indexable [index]
- steam/game_server.py:146: error: Argument "type" to "Query" has incompatible type "Type[list[Any]]"; expected "Union[Type[list[str]], tuple[Type[list[str]], ...], None]" [arg-type]
+ steam/game_server.py:146: error: Argument "type" to "Query" has incompatible type "Type[list[Any]]"; expected "Type[list[str]] | tuple[Type[list[str]], ...] | None" [arg-type]
- steam/game_server.py:151: error: Argument "type" to "Query" has incompatible type "Type[list[Any]]"; expected "Union[Type[list[str]], tuple[Type[list[str]], ...], None]" [arg-type]
+ steam/game_server.py:151: error: Argument "type" to "Query" has incompatible type "Type[list[Any]]"; expected "Type[list[str]] | tuple[Type[list[str]], ...] | None" [arg-type]
- steam/game_server.py:156: error: Argument "type" to "Query" has incompatible type "Type[list[Any]]"; expected "Union[Type[list[str]], tuple[Type[list[str]], ...], None]" [arg-type]
+ steam/game_server.py:156: error: Argument "type" to "Query" has incompatible type "Type[list[Any]]"; expected "Type[list[str]] | tuple[Type[list[str]], ...] | None" [arg-type]
- steam/game_server.py:259: error: Argument "callback" to "Query" has incompatible type "Optional[Callable[[Any], Any]]"; expected "Callable[[T_co], Any]" [arg-type]
+ steam/game_server.py:259: error: Argument "callback" to "Query" has incompatible type "Callable[[Any], Any] | None"; expected "Callable[[T_co], Any]" [arg-type]
- steam/game_server.py:278: error: Incompatible return value type (got "Union[Query[Any], str]", expected "str") [return-value]
+ steam/game_server.py:278: error: Incompatible return value type (got "Query[Any] | str", expected "str") [return-value]
- steam/abc.py:196: error: Incompatible types in assignment (expression has type "steam.comment.Comment", variable has type "Optional[steam.protobufs.comments.GetCommentThreadResponse.Comment]") [assignment]
+ steam/abc.py:196: error: Incompatible types in assignment (expression has type "steam.comment.Comment", variable has type "steam.protobufs.comments.GetCommentThreadResponse.Comment | None") [assignment]
- steam/abc.py:556: note: Left operand is of type "Optional[datetime]"
+ steam/abc.py:556: note: Left operand is of type "datetime | None"
- steam/abc.py:556: note: Right operand is of type "Optional[datetime]"
+ steam/abc.py:556: note: Right operand is of type "datetime | None"
- steam/abc.py:749: error: No overload variant of "fetch_server" of "Client" matches argument types "Union[IPv4Address, IPv6Address]", "object" [call-overload]
+ steam/abc.py:749: error: No overload variant of "fetch_server" of "Client" matches argument types "IPv4Address | IPv6Address", "object" [call-overload]
- steam/abc.py:749: note: def fetch_server(self, *, id: Union[SupportsInt, SupportsIndex, str, bytes]) -> Coroutine[Any, Any, Optional[GameServer]]
+ steam/abc.py:749: note: def fetch_server(self, *, id: SupportsInt | SupportsIndex | str | bytes) -> Coroutine[Any, Any, GameServer | None]
- steam/abc.py:749: note: def fetch_server(self, *, ip: Union[IPv4Address, str], port: int = ...) -> Coroutine[Any, Any, Optional[GameServer]]
+ steam/abc.py:749: note: def fetch_server(self, *, ip: IPv4Address | str, port: int = ...) -> Coroutine[Any, Any, GameServer | None]
- steam/user.py:378: error: Argument "type" to "parse_id64" has incompatible type "int"; expected "Optional[Type]" [arg-type]
+ steam/user.py:378: error: Argument "type" to "parse_id64" has incompatible type "int"; expected "Type | None" [arg-type]
- steam/published_file.py:506: error: List comprehension has incompatible type List[Optional[Friend]]; expected List[Friend] [misc]
+ steam/published_file.py:506: error: List comprehension has incompatible type List[Friend | None]; expected List[Friend] [misc]
- steam/event.py:271: error: Incompatible types in assignment (expression has type "Union[IPv4Address, str, None]", variable has type "Optional[IPv4Address]") [assignment]
+ steam/event.py:271: error: Incompatible types in assignment (expression has type "IPv4Address | str | None", variable has type "IPv4Address | None") [assignment]
- steam/http.py:465: error: Argument "type" to "parse_id64" has incompatible type "int"; expected "Optional[Type]" [arg-type]
+ steam/http.py:465: error: Argument "type" to "parse_id64" has incompatible type "int"; expected "Type | None" [arg-type]
- steam/http.py:589: error: Item "None" of "Union[timedelta, None, Any]" has no attribute "total_seconds" [union-attr]
+ steam/http.py:589: error: Item "None" of "timedelta | Any | None" has no attribute "total_seconds" [union-attr]
- steam/http.py:589: error: Item "None" of "Optional[tzinfo]" has no attribute "utcoffset" [union-attr]
+ steam/http.py:589: error: Item "None" of "tzinfo | None" has no attribute "utcoffset" [union-attr]
- steam/http.py:599: error: Item "None" of "Optional[tzinfo]" has no attribute "utcoffset" [union-attr]
+ steam/http.py:599: error: Item "None" of "tzinfo | None" has no attribute "utcoffset" [union-attr]
- steam/http.py:600: error: Item "None" of "Union[timedelta, None, Any]" has no attribute "total_seconds" [union-attr]
+ steam/http.py:600: error: Item "None" of "timedelta | Any | None" has no attribute "total_seconds" [union-attr]
- steam/http.py:875: error: Value of type "Optional[Match[str]]" is not indexable [index]
+ steam/http.py:875: error: Value of type "Match[str] | None" is not indexable [index]
- steam/gateway.py:490: error: Argument "type" to "parse_id64" has incompatible type "int"; expected "Optional[Type]" [arg-type]
+ steam/gateway.py:490: error: Argument "type" to "parse_id64" has incompatible type "int"; expected "Type | None" [arg-type]
- steam/gateway.py:490: error: Argument "universe" to "parse_id64" has incompatible type "int"; expected "Optional[Universe]" [arg-type]
+ steam/gateway.py:490: error: Argument "universe" to "parse_id64" has incompatible type "int"; expected "Universe | None" [arg-type]
... (truncated 310 lines) ...
operator (https://github.com/canonical/operator)
- ops/lib/__init__.py:262: error: Item "None" of "Optional[Loader]" has no attribute "exec_module" [union-attr]
+ ops/lib/__init__.py:262: error: Item "None" of "Loader | None" has no attribute "exec_module" [union-attr]
- ops/pebble.py:878: error: Incompatible types in assignment (expression has type "Union[ServiceStartup, str]", variable has type "ServiceStartup") [assignment]
+ ops/pebble.py:878: error: Incompatible types in assignment (expression has type "ServiceStartup | str", variable has type "ServiceStartup") [assignment]
- ops/pebble.py:882: error: Incompatible types in assignment (expression has type "Union[ServiceStatus, str]", variable has type "ServiceStatus") [assignment]
+ ops/pebble.py:882: error: Incompatible types in assignment (expression has type "ServiceStatus | str", variable has type "ServiceStatus") [assignment]
- ops/pebble.py:1017: error: Incompatible types in assignment (expression has type "Union[FileType, str]", variable has type "FileType") [assignment]
+ ops/pebble.py:1017: error: Incompatible types in assignment (expression has type "FileType | str", variable has type "FileType") [assignment]
- ops/pebble.py:1085: error: Incompatible types in assignment (expression has type "Union[CheckLevel, str, None]", variable has type "CheckLevel") [assignment]
+ ops/pebble.py:1085: error: Incompatible types in assignment (expression has type "CheckLevel | str | None", variable has type "CheckLevel") [assignment]
- ops/pebble.py:1089: error: Incompatible types in assignment (expression has type "Union[CheckStatus, str]", variable has type "CheckStatus") [assignment]
+ ops/pebble.py:1089: error: Incompatible types in assignment (expression has type "CheckStatus | str", variable has type "CheckStatus") [assignment]
- ops/pebble.py:1238: error: Incompatible types in assignment (expression has type "Optional[BytesIO]", variable has type "Optional[StringIO]") [assignment]
+ ops/pebble.py:1238: error: Incompatible types in assignment (expression has type "BytesIO | None", variable has type "StringIO | None") [assignment]
- ops/pebble.py:1343: error: Argument 1 of "write" is incompatible with supertype "BufferedIOBase"; supertype defines the argument type as "Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]]" [override]
+ ops/pebble.py:1343: error: Argument 1 of "write" is incompatible with supertype "BufferedIOBase"; supertype defines the argument type as "bytes | bytearray | memoryview | array[Any] | mmap | _CData | PickleBuffer" [override]
- ops/pebble.py:1367: error: Return type "Union[str, bytes]" of "read" incompatible with return type "bytes" in supertype "BufferedIOBase" [override]
+ ops/pebble.py:1367: error: Return type "str | bytes" of "read" incompatible with return type "bytes" in supertype "BufferedIOBase" [override]
- ops/pebble.py:1367: error: Argument 1 of "read" is incompatible with supertype "BufferedIOBase"; supertype defines the argument type as "Optional[int]" [override]
+ ops/pebble.py:1367: error: Argument 1 of "read" is incompatible with supertype "BufferedIOBase"; supertype defines the argument type as "int | None" [override]
- ops/pebble.py:1400: error: Return type "Union[str, bytes]" of "read1" incompatible with return type "bytes" in supertype "BufferedIOBase" [override]
+ ops/pebble.py:1400: error: Return type "str | bytes" of "read1" incompatible with return type "bytes" in supertype "BufferedIOBase" [override]
- ops/log.py:70: error: Incompatible types in assignment (expression has type "Callable[[Type[BaseException], BaseException, TracebackType], Any]", variable has type "Callable[[Type[BaseException], BaseException, Optional[TracebackType]], Any]") [assignment]
+ ops/log.py:70: error: Incompatible types in assignment (expression has type "Callable[[Type[BaseException], BaseException, TracebackType], Any]", variable has type "Callable[[Type[BaseException], BaseException, TracebackType | None], Any]") [assignment]
- ops/model.py:783: note: def get(self, str, /) -> Optional[Binding]
+ ops/model.py:783: note: def get(self, str, /) -> Binding | None
- ops/model.py:783: note: def [_T] get(self, str, /, default: Union[Binding, _T]) -> Union[Binding, _T]
+ ops/model.py:783: note: def [_T] get(self, str, /, default: Binding | _T) -> Binding | _T
- ops/model.py:783: note: def get(self, binding_key: Union[str, Relation]) -> Binding
+ ops/model.py:783: note: def get(self, binding_key: str | Relation) -> Binding
- ops/model.py:783: note: def get(self, str, /) -> Optional[Binding]
+ ops/model.py:783: note: def get(self, str, /) -> Binding | None
- ops/model.py:783: note: def [_T] get(self, str, /, default: Union[Binding, _T]) -> Union[Binding, _T]
+ ops/model.py:783: note: def [_T] get(self, str, /, default: Binding | _T) -> Binding | _T
- ops/model.py:783: note: def get(self, binding_key: Union[str, Relation]) -> Binding
+ ops/model.py:783: note: def get(self, binding_key: str | Relation) -> Binding
- ops/model.py:884: error: Incompatible types in assignment (expression has type "Optional[str]", variable has type "str") [assignment]
+ ops/model.py:884: error: Incompatible types in assignment (expression has type "str | None", variable has type "str") [assignment]
- ops/model.py:948: error: Incompatible types in assignment (expression has type "Optional[str]", variable has type "str") [assignment]
+ ops/model.py:948: error: Incompatible types in assignment (expression has type "str | None", variable has type "str") [assignment]
- ops/model.py:2121: error: Argument 2 to "_list_recursive" of "Container" has incompatible type "Union[str, Path]"; expected "Path" [arg-type]
+ ops/model.py:2121: error: Argument 2 to "_list_recursive" of "Container" has incompatible type "str | Path"; expected "Path" [arg-type]
- ops/model.py:2196: error: Argument 2 to "_list_recursive" of "Container" has incompatible type "Union[str, Path]"; expected "Path" [arg-type]
+ ops/model.py:2196: error: Argument 2 to "_list_recursive" of "Container" has incompatible type "str | Path"; expected "Path" [arg-type]
- ops/model.py:2616: note: def run(args: Union[Union[str, bytes, PathLike[str], PathLike[bytes]], Sequence[Union[str, bytes, PathLike[str], PathLike[bytes]]]], bufsize: int = ..., executable: Optional[Union[str, bytes, PathLike[str], PathLike[bytes]]] = ..., stdin: Union[None, int, IO[Any]] = ..., stdout: Union[None, int, IO[Any]] = ..., stderr: Union[None, int, IO[Any]] = ..., preexec_fn: Optional[Callable[[], Any]] = ..., close_fds: bool = ..., shell: bool = ..., cwd: Optional[Union[str, bytes, PathLike[str], PathLike[bytes]]] = ..., env: Optional[Union[Mapping[bytes, Union[str, bytes, PathLike[str], PathLike[bytes]]], Mapping[str, Union[str, bytes, PathLike[str], PathLike[bytes]]]]] = ..., universal_newlines: Optional[bool] = ..., startupinfo: Any = ..., creationflags: int = ..., restore_signals: bool = ..., start_new_session: bool = ..., pass_fds: Collection[int] = ..., *, capture_output: bool = ..., check: bool = ..., encoding: Optional[str] = ..., errors: Optional[str] = ..., input: Optional[str] = ..., text: Literal[True], timeout: Optional[float] = ..., user: Union[str, int, None] = ..., group: Union[str, int, None] = ..., extra_groups: Optional[Iterable[Union[str, int]]] = ..., umask: int = ..., pipesize: int = ...) -> CompletedProcess[str]
... (truncated 588 lines) ...``` |
JukkaL
approved these changes
Apr 24, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! This looks great, and really improves usability for users targeting Python 3.10 or later.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This should fix #15082:
If the python version is set to 3.10 or later union error reports are going to be displayed using the
X | Y
syntax.If None is found in a union it is shown as the last element in order to improve visibility (
Union[bool, None, str]
becomes"bool | str | None"
.To achieve this an option
use_or_syntax()
is created that is set to true if the python version is 3.10 or later.For testing a hidden flag --force-union-syntax is used that sets the option to false.