Skip to main content
0 votes
0 answers
24 views

Add an optional keyword argument to the signature of a python function? [duplicate]

I have a python decorator, apply_suffix which adds a suffix keyword argument to a python function. import functools def add_suffix(func): @functools.wraps(func) def wrapper(*args, suffix: str ...
illusional's user avatar
0 votes
0 answers
36 views

How to create a variadic generic container with heterogeneous types in Python 3.13 using PEP 646 and PEP 695?

I'm experimenting with PEP 646 Variadic Generics and PEP 695 Class/Function Scoped TypeVars in Python 3.13. My goal is to create a heterogeneous container that stores items (functions, in this example)...
Arthur Brenno's user avatar
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 ...
sumid's user avatar
  • 2,051
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, ...
平田智剛's user avatar
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....
平田智剛's user avatar
0 votes
1 answer
42 views

Pyre: `Invalid class instantiation` on a factory pattern with ABC type hint

I have implemented a factory pattern but Pyre-check trips over the type-hinting, thinking I want to instantiate the mapping dict type hint: type[MyClassABC] Here is a minimum example, also a pyre-...
Rien's user avatar
  • 458
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 ...
Pierre-olivier Gendraud's user avatar
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 ...
cdwilson's user avatar
  • 4,432
1 vote
0 answers
60 views

Pyre-check error for @property: Undefined attribute: `<class>` has no attribute `<attribute>`

I use pyre-check for type checking my python code, with strict setting on. It works fine except for OOP properties. Example code: class MyClass: def __init__(self, full_name: str): self....
Rien's user avatar
  • 458
0 votes
0 answers
36 views

How to make IDE type-checking recognize dynamically added methods from a class decorator in Python?

This is my code: from typing import Type, TypeVar T = TypeVar("T") class NewMethodsMixin: def new_method(self) -> str: """This is a new method added by a ...
owl sandy's user avatar
2 votes
1 answer
27 views

How to have Pyright infer type from an enum check?

Can types be associated with enums, so that Pyright can infer the type from an equality check? (Without cast() or isinstance().) from dataclasses import dataclass from enum import Enum, auto class ...
Q42's user avatar
  • 23
0 votes
1 answer
114 views

Python typing warning when overriding a method with different returns depending on parameters

Here is an example of my issue from typing import Literal, overload @overload def do_something(a: str, b: str="", no_return: Literal[False]=False) -> str: ... @overload def do_something(...
dododingo's user avatar
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, ...
Gronnmann's user avatar
1 vote
0 answers
37 views

Python typing is rejecting override of a property with a child of its type

Here is an example of my issue: class Foo: pass class FooChild(Foo): pass class Bar: def __init__(self): self.prop: Foo class BarChild(Bar): def __init__(self): self....
dododingo's user avatar
0 votes
1 answer
74 views

Type hints for a function (multiprocessing)

The following function creates an instance of a class that can be shared between processes: def create_shared_object (constructor: ?) -> ?: from multiprocessing.managers import BaseManager; ...
isa-2d's user avatar
  • 31

15 30 50 per page
1
2 3 4 5
263