profile
viewpoint
Yegor Roganov roganov Kiev, Ukraine

roganov/aiohttp 0

Async http client/server framework (asyncio)

roganov/aioreloader 0

Port of tornado reloader to asyncio

roganov/aws-sdk-go 0

AWS SDK for the Go programming language.

roganov/cantal-py 0

Python library for cantal

roganov/cli 0

A simple, fast, and fun package for building command line apps in Go

roganov/django-nose 0

Django test runner using nose

roganov/proposal 0

Go Project Design Documents

issue openedmicrosoft/pyright

"Type[Exception]" is not iterable error when handling exception

Describe the bug pyright is reporting a weird error "Type[Exception]" is not iterable when handling exceptions.

To Reproduce

from typing import Type


class Exceptions:
    exc: Type[Exception] = Exception


try:
    1/0
except Exceptions().exc:
    print('exc')

Expected behavior No errors

created time in 3 months

issue commentmicrosoft/pyright

__contains__ should narrow Optional[T] to T

Thank you.

roganov

comment created time in 3 months

issue openedmicrosoft/pyright

__contains__ should narrow Optional[T] to T

__contains__ should narrow Optional[T] to T

To Reproduce

from typing import Optional
import random


def foo(p: str) -> None:
    print(p)


x: Optional[str]
if random.random() < 0.5:
    x = None
else:
    x = '2'

if x in ['2']:
    foo(x)

Describe the bug x can not be None on the last line of this program, but error is reported:

  16:9 - error: Argument of type "str | None" cannot be assigned to parameter "p" of type "str" in function "foo"
  Type "None" cannot be assigned to type "str"
    Type "None" cannot be assigned to type "str" (reportGeneralTypeIssues)

Expected behavior No errors

Screenshots or Code If applicable, add screenshots or the text of the code (surrounded by triple back ticks) to help explain your problem.

def foo(self) -> str:
    return 3

created time in 3 months

more