Skip to main content
Filter by
Sorted by
Tagged with
-1 votes
1 answer
57 views

The binary_var_list method in the docplex.mp.model API has an incorrect type annotation for the name parameter. Current signature: def binary_var_list(self, keys, lb=None, ub=None, name: type[str] = ...
pipefish's user avatar
  • 1,036
1 vote
1 answer
64 views

I am currently defining ORMs and DTOs in my fastapi application, and using SQLAlchemy 2.0 for this job. Many sources, including the official docs, specify that the way to use mapped types with ORMs is ...
xxixx's user avatar
  • 11
1 vote
0 answers
67 views

TL;DR Suppose a Python library defines an interface meant to be implemented by third-party code. How could this library provide a factory function that creates instances of those implementations, with ...
mgab's user avatar
  • 4,054
-4 votes
0 answers
90 views

Say I have a Pydantic model that can take an Any type. If the user sends in JSON on their end, what will Pydantic do here? Will it fail, or will request be of some known type? Ultimately, I know ...
ammo 45's user avatar
0 votes
0 answers
47 views

I have the following abstract Data class and some concrete subclasses: import abc from typing import TypeVar, Generic, Union from pydantic import BaseModel T = TypeVar('T') class Data(BaseModel, abc....
Relys's user avatar
  • 85
1 vote
1 answer
81 views

Python 3.12 introduced new syntax sugar for generics. What's the new way of writing an upper-bounded generic like this: def foo[T extends Bar](baz: T) -> T: ... Before new syntax features I ...
detectivekaktus's user avatar
1 vote
1 answer
122 views

When I define a class attribute named type, a type[Foo] annotation inside the same class causes mypy to report that the type name is a variable and therefore “not valid as a type”. class Foo: type:...
J Kluseczka's user avatar
  • 1,747
1 vote
1 answer
107 views

I want to annotate a type parameter for a generic dataclass of mine with a Google style docstring to both support generating documentation and mouse hovering within VS Code (and other editors/IDEs). ...
Snap's user avatar
  • 868
0 votes
1 answer
91 views

I'm trying to type hint my fastAPI to take both a BaseModel pydantic class for various arguments and some seperate files. I also want to add a description for all of the inputs on http://127.0.0.1:...
Felix's user avatar
  • 1
1 vote
2 answers
108 views

Preamble I'm using polars's write_excel method which has a parameter column_formats which wants a ColumnFormatDict that is defined here and below ColumnFormatDict: TypeAlias = Mapping[ # dict of ...
Dean MacGregor's user avatar
4 votes
0 answers
100 views

I want to narrow an unambiguously defined dict[...] type in a superclass to a specific TypedDict in an inheriting class but I cannot figure out a way to specify a dict-based supertype that the ...
bossi's user avatar
  • 1,744
1 vote
1 answer
141 views

How can I implement DecoratorFactory such that it type-checks as follows: def accepts_foo(foo: int): ... def accepts_bar(bar: int): ... decorator_foo = DecoratorFactory(foo=1) decorator_foo(...
obk's user avatar
  • 856
1 vote
2 answers
116 views

I am trying to annotate a function which receives a tuple of types, and returns a value of one of the provided types. For example: @overload def func[T1](types: tuple[type[T1]]) -> T1: ... @...
alecov's user avatar
  • 5,262
0 votes
0 answers
127 views

I'm trying to type hint my telnetlib3 client. However, I have some utility code which should not depend on telnet. It should be able to deal with asyncio StreamReader/Writer in common. Now, if I pass ...
Wör Du Schnaffzig's user avatar
0 votes
0 answers
115 views

I wanted to override the structlog logger for the whole application, by doing this: import enum from collections.abc import Iterable import structlog from structlog.typing import Processor from ...
comonadd's user avatar
  • 2,018
0 votes
0 answers
72 views

I am using pydantic with placeholders interpolation in field values: from typing import Any from pydantic import BaseModel class Model(BaseModel): _placeholders: dict[str, Any] a: int = "{...
maejam's user avatar
  • 1
-1 votes
1 answer
57 views

My goal is to handle multiple functions that are chained and create outputs in dictionaries that are summarized and handed over in a chain. To assert types and that certain keys are present, I am ...
Engensmax's user avatar
  • 173
0 votes
1 answer
108 views

Is there a way to make a generic class A[T], which has a function that inherits the type for the same function in T? I want to make something like these 2 classes: class A[T]: ... def a(self): ...
Bobi's user avatar
  • 29
4 votes
2 answers
126 views

I'm currently in trouble to understand TypeVar and Generic in Python. Here's the setting of my MWE (Minimal Working Example) : I defined an abstract class, which has a __call__ method: This method ...
python_is_superbe's user avatar
6 votes
2 answers
218 views

I would like to annotate both parameters of a function – supposed to perform simple comparison between them ­– in order to indicate that their types should be the same and should support simple ...
Vexx23's user avatar
  • 173
1 vote
0 answers
49 views

I am in a scenario (that could be compared to writing an AST) where I compile multiple regex patterns that I want to reuse later, and for the sake of simplicity and readability I want to store them in ...
globglogabgalab's user avatar
1 vote
1 answer
119 views

I want to set and instantiate the right type based on the value of another field and get typing and autocomplete on it. I want this to happen automatically when the class is instantiated: ...
red888's user avatar
  • 32.3k
3 votes
3 answers
214 views

I need to type-hint that a value is either some TypedDict or a completely empty dict. The TypedDict itself already exists and is non-trivial, and it's an all-or-nothing situation – so modifying the ...
MisterMiyagi's user avatar
  • 53.4k
0 votes
1 answer
86 views

I have a relative simple app in which I use a Message Bus to pass messages. I prefer a bit more stricter type checking: rather than passing arbitrary text strings as topic, I pass message objects, and ...
MacFreek's user avatar
  • 3,568
2 votes
0 answers
68 views

Assume I have a callable type with some arbitrary set of argument types: Callable[[T1, T2, T3, <etc>, Tn], str] Is there a way (presumably using TypeVarTuple or ParamSpec) to statically ...
Sebastian Lenartowicz's user avatar

1
2 3 4 5
87