jaraco / jaraco/inflect

Pyright incompatibility

Open
#210 3 comments 3 reactions 0 assignees View on GitHub
help wanted
Dominant language
Python
Stars
1.1k
Forks
127
PR merge metrics
No merged PRs in 30d

Description

The trick [explained here](https://github.com/agronholm/typeguard/issues/353#issuecomment-1656741153) used to make typegaurd use the runtime types but MyPy use the static-type-checking types sadly does not work with Pyright.

```python
from typing import TYPE_CHECKING, Any, TypeAlias, reveal_type

_STATIC_TYPE_CHECKING = TYPE_CHECKING # workaround for typeguard

if _STATIC_TYPE_CHECKING:
Foo: TypeAlias = Any
else:
class MetaFoo(type):
def __instancecheck__(cls, obj):
...
class Foo(metaclass=MetaFoo): # type: ignore[no-redef]
pass

if TYPE_CHECKING:
Bar: TypeAlias = Any
else:
class MetaBar(type):
def __instancecheck__(cls, obj):
...
class Bar(metaclass=MetaBar): # type: ignore[no-redef]
pass

reveal_type(Foo) # pyright output: Type of "Foo" is "Type[Foo]"
reveal_type(Bar) # pyright output: Type of "Bar" is "Any"
```

So this gives an error:

```python
import inflect

p = inflect.engine()

p.plural("apple") # Argument of type "Literal['apple']" cannot be assigned to parameter "text" of type "Word" in function "plural"
#  "Literal['apple']" is incompatible with "Word" [reportArgumentType]

```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the shown Pyright error for p.plural("apple") and compare it with the TYPE_CHECKING workaround and the Word type referenced in the diagnostic. Done means the example is accepted by Pyright without breaking the intended runtime typing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.