Skip to content

Suggest using PEP 604-style union types #45

@hoefling

Description

@hoefling

Humble suggestion: add new code to suggest a replacement of Union[...] types with the | chain, e.g. Y093 Use PEP 604 union types. A simple implementation start could be e.g.

class PyVisitor(ast.NodeVisitor):
    ...
     def visit_FunctionDef(self, node):
        if node.returns.value is not None and node.returns.value.id in ("Optional", "Union"):
            self.error(node.returns, Y093)
        ...

    def visit_arguments(self, node):
        if arg.annotation.value.id in ("Optional", "Union"):
            self.error(arg, Y093)
        ...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions