Skip to content

Exception handling not working. #6091

Closed
@sp1rs

Description

@sp1rs
from typing import Union

def post(path: str) -> Union[requests.models.Response, ManualException]
      try:
            return requests.post(path)
      except:  
            raise ManualException 


def call() -> List:
        try:
              resp = post('path')
        except ManualException:
               return []

        return resp.content

On running mypy

Item "ManualException" of "Union[Response, ManualException]" has no attribute "content"

Ideally mypy should not raise any error, because I am handling the case when exception is raised.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions