Skip to content
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

type error when change "Union" operator to "|" operator #925

Closed
MSafariyan opened this issue Dec 24, 2023 · 1 comment
Closed

type error when change "Union" operator to "|" operator #925

MSafariyan opened this issue Dec 24, 2023 · 1 comment

Comments

@MSafariyan
Copy link

requires-python = ">=3.11"
  - repo: https://github.com/asottile/pyupgrade
    rev: v3.15.0
    hooks:
      - id: pyupgrade
        args:
          - --py311-plus

currently i have a similar method:

from collections.abc import Awaitable

class RedisPort:
    @abstractmethod
-   def srem(self, name: str, *values: bytes | str | float) -> Union[Awaitable[int], int]:
+   def srem(self, name: str, *values: bytes | str | float) -> Awaitable[int] | int:
        raise NotImplementedError

then pyupgrade try to change Union operator to | so the python raise TypeError exception:

(<class 'TypeError'>, unsupported operand type(s) for |: 'types.GenericAlias' and 'function', <traceback object at 0x7f2a3223f080>)

@asottile
Copy link
Owner

when you instruct pyupgrade to --py311-plus you're telling it "I only run python 3.11 or newer" -- your error message is from python 3.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants