All Questions
Tagged with mypy python-typing
1,232 questions
0
votes
1
answer
48
views
How do I initialize empty variable for boto3 client
I'd like to do a simple check if a variable for boto3 client is empty. I tried following approach:
"""Example of boto3 client lazy initialization"""
from typing import ...
1
vote
1
answer
93
views
How to prevent type alias defined in a stub file from being used in other modules?
I'm working on a Python 3.13.1 project using mypy 1.14.0 for static type checking.
I have a module named module.py with a function function that returns a type with a very long name,
...
4
votes
1
answer
106
views
Is this a false positive [override] error? "Signature of (method) incompatible with supertype"
Although the method signature in Sub is compatible with Super, mypy rejects the override: Signature of "method" incompatible with supertype "Super".
I'm using
python 3.13.1
mypy 1....
4
votes
2
answers
93
views
How to make mypy correctly type-check a function using functools.partial?
I'm trying to create a function that returns a partially applied callable, but I'm encountering issues with mypy type checking.
HEre Is my first implementation:
Help me to explain my question for ...
1
vote
1
answer
128
views
How to add Python type annotations to a class that inherits from itself?
I'm trying add type annotations to an ElementList object that inherits from list and can contain either Element objects or other ElementGroup objects.
When I run the following code through mypy:
from ...
0
votes
0
answers
28
views
Select query in SQLAlchemy with mypy - Argument 1 to "where" of "Select" has incompatible type "bool"; expected "ColumnElement[bool]
When querying some params in an endpoint:
duplicate_integration = select(Integration).where(
integration_create.provider_accounting_id == Integration.provider_accounting_id,
...
0
votes
0
answers
49
views
Python typing for a generic instance method decorator [duplicate]
I am creating a generic decorator for an instance method:
def my_dec(func):
def wrapper(self, *args, **kwargs):
print("do something")
return func(self, *args, **kwargs)
...
1
vote
1
answer
138
views
Static typing of Python regular expression: 'incompatible type "str"; expected "AnyStr | Pattern[AnyStr]" '
Just to be clear, this question has nothing to do with the regular expression itself and my code is perfectly running even though it is not passing mypy strict verification.
Let's start from the basic,...
0
votes
1
answer
99
views
mypy reporting error in generic function on return statement
With the code below
def incr[T: int | None](value: T) -> T:
if value is None:
return value
return value + 1
incr(None)
incr(1)
Running mypy gives error:
main.py:4: error: Incompatible return ...
0
votes
0
answers
44
views
How to use **kwargs with MyPy [duplicate]
Consider the following code, which I would like to type-check:
def foo(add_count: bool = False) -> int:
return 5 if add_count else 0
def A(x: int, y: int, **kwargs: dict) -> int:
return ...
1
vote
2
answers
120
views
Is it possible to type annotate Python function parameter used as TypedDict key to make mypy happy?
While working through code challenges I am trying to use type annotations for all function parameters/return types. I use mypy in strict mode with the goal of no errors.
I've spent some time on this ...
0
votes
1
answer
31
views
How can use statically typed check a dataclass create with make_dataclass
When i create and use a dataclass the "normal way" I can run and type check my code mypy without problem.
For instance, this code works perfectly fine:
@dataclass
class Person2:
name : ...
1
vote
3
answers
61
views
How do I type hint a frame object in Python?
I'm type hinting a large existing Python codebase, and in one part it sets a signal handler using signal.signal. The signal handler is a custom function defined in the codebase, so I need to type hint ...
0
votes
0
answers
81
views
Why does unpacking with the new generic syntax in Python 3.13 cause a mypy error?
I am trying to use the new generic type syntax introduced in Python 3.13 for defining type aliases with unpacking (*). While the code executes correctly, mypy raises a type-checking error. The same ...
1
vote
2
answers
89
views
How to build a type from another type and make mypy checking work
I'm working with Python's type hinting system and I'm trying to create a type alias for a function that's similar to an existing function type, but with one additional argument. Here's what I've ...