Skip to main content
New: Stack Overflow For Agents. The next generation of knowledge exchange. Learn more
Filter by
Sorted by
Tagged with
1 vote
1 answer
88 views

I have a Python function that accepts a socket.AddressFamily argument. import socket def fn(family: socket.AddressFamily) -> None: ... This works fine. However, intersphinx doesn’t know this ...
Remco Haszing's user avatar
0 votes
1 answer
93 views

I have a Python method that only works on a constrained subsets of a generic class. As as constructed example, I might want Spam.floatify in the following code to only be available for instances of ...
Anerdw's user avatar
0 votes
0 answers
139 views

I am testing the new Python 3.14 annotationlib module to build a dynamic validation tool. I want to inspect annotations lazily without causing import circular dependencies. The problem is that if my ...
AstroBrick's user avatar
-3 votes
0 answers
55 views

I'm trying to understand the methods defined in gdsfactory, a project for laying out components for integrated circuit wafers. Each component is defined by the class Component, in which you put ...
Eve's user avatar
3 votes
1 answer
161 views

I am upgrading a codebase to Python 3.12 and migrating our generic classes to use the new PEP 695 syntax, e.g.: class Box[T]: ... instead of: T = TypeVar('T') class Box(Generic[T]): ... Most ...
unknown's user avatar
Advice
2 votes
1 replies
70 views

I have a function comma_separated_list_ex currently implemented as such def comma_separated_list_ex[T: Lexeme](self, typ: type[T] | tuple[type[T], ...], fin: type[Lexeme]) -> tuple[ list[T],...
Serinice's user avatar
2 votes
2 answers
309 views

I want to type a decorator, that is a callable that returns a callable. I want to type this on a way that validate at the moment of decoration that the args and returns type are correct, but also ...
Pablo Estevez's user avatar
3 votes
2 answers
133 views

_Item = TypeVar("_Item", BaseItem) @app.get(path="items") def get_items() -> list[_Item]: return _get_items() Pylance complains: TypeVar "_Item" appears only ...
Thanasis Mattas's user avatar
Advice
6 votes
3 replies
169 views

Afternoon, Is it possible in python, given a function that takes a generic sequence of objects, to type it so that the list must be of only one type and not a union of multiple children? for code like ...
Frostyfeet909's user avatar
3 votes
0 answers
141 views

Is there an existing tool or pattern that statically verifies type compatibility across pipeline stage boundaries — where stages are defined in Python, configured in YAML, and validated with JSON ...
Kenneth Douglas's user avatar
1 vote
2 answers
114 views

I have a function that extract info on any kind of variable, and returns it, so it can be embedded in a code without the need to rewrite another line. It is defined as such: from typing import TypeVar ...
Lrx's user avatar
Best practices
0 votes
2 replies
94 views

If I write a wrapper around a function, how can I type *args and **kwargs properly? In this tiny example (just a tiny self contained minimal code, not meant to relate to what exists in real life) # ...
Guillaume's user avatar
Advice
3 votes
8 replies
256 views

TLDR; is there a way to make UserString be accepted as str, or to define a class that inherits from str and then intercept access to self in the str (to modify before returning it)? We want to apply ...
user8557834's user avatar
Best practices
0 votes
4 replies
99 views

I am trying to create a dataclass from a dynamically created class. I am doing something like [1] A = dataclass(type("ClsA", (), {"a":1})) However, the attribute a is not ...
A. Gocht's user avatar
4 votes
1 answer
192 views

I have the following code from typing import Protocol, runtime_checkable @runtime_checkable class A(Protocol): def f(self): ... class B: def f(self): ... if __name__ == '__main__': ...
haferfleks's user avatar

15 30 50 per page
1
2 3 4 5
289