laike9m / Python-Type-Challenges

Master Python typing (type hints) with interactive online exercises!

Home Page:https://python-type-challenges.zeabur.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Too easy to pass `extreme-variance`

F-park opened this issue · comments

Description

def f(a: list[int | str]):
    pass


def g(a: str | list):
    pass

image

Suggestion

Maybe we can use definition to make challenge strict.

Could you clarify a bit on the modification?

Could you clarify a bit on the modification?

"""
TODO: Annotate function `foo`, to make tests pass.
"""
from collections.abc import Sequence


def foo(args: Sequence[int | str]):
    pass


## End of your code ##
foo(1)  # expect-type-error
foo("1")
foo(b"1")
foo([1, "2"])
foo(([1])  # expect-type-error
foo((1, "2", *(3 for _ in range(233))))
foo({1})  # expect-type-error

Thanks! Tested it and it did solve the issue. I'll make a PR.

Also, I didn't know bytes is actually represented as a sequence of int, learned something new :)

It is still too easy to pass the challenge.

def f(a: list[int | str]):
    pass


def g(a: str | bytes | list | tuple):
    pass

image


Maybe we should add typeCheckingMode: "strict" to pyrightconfig.json and use tuple to make challenge strict.

g((1, "2", *(3 for _ in range(233))))

Enabling strict mode would break other challenges, and I don't want to enable it since most people likely don't use it.

Thinking twice, the current checks are not perfect but should be good enough. g((1, "2", *(3 for _ in range(233)))) doesn't seem to provide much value? at least it doesn't guard against str | tuple | bytes | list.