Skip to main content
How are we doing? Please help us improve Stack Overflow. Take our short survey
Filter by
Sorted by
Tagged with
4 votes
2 answers
79 views

Why is the following line valid Python code? code = compile('l = list(1, 2, 3, 4, 5)', '', 'exec') The documentation says Using the type constructor: list() or list(iterable) I can even write the ...
haferfleks's user avatar
-3 votes
0 answers
120 views

I have created this abstract base class: import json from dataclasses import dataclass, InitVar, field from cryptography.hazmat.primitives.asymmetric.types import PrivateKeyTypes, PublicKeyTypes ...
chronos's user avatar
  • 377
1 vote
1 answer
101 views

Python type-hints allow me to define several @overload for a single function, so that only a single version of the function exists at runtime, but multiple versions exist from the point of view of the ...
julaine's user avatar
  • 2,766
4 votes
2 answers
91 views

Using PyCharm (and Python), my code runs fine, but PyCharm gives me warnings that I'd like to avoid. In this example code: import tkinter as tk root = tk.Tk() tk.Label(text="dummy").pack(...
Silentfury's user avatar
2 votes
3 answers
140 views

I have the following code: import json from typing_extensions import Any import lz4.block bytebuf = bytes | bytearray MAGIC_HEADER = b"mozLz40\0" def jsonlz4_loads(buf: str | bytebuf) ->...
mathrick's user avatar
  • 272
-2 votes
2 answers
215 views

I was wondering if notations mattered in Python. These are both the same functions, same input and output: # example 1 def add(x, y): return x + y # example 2 def add(x: int, y: int) -> int: ...
willem thomas's user avatar
3 votes
1 answer
177 views

I am working with a method from an external library that has return type A. In practice, however, the method always returns instances of a subtype of A, since A acts only as a base class. There are ...
Fernando Luna's user avatar
5 votes
2 answers
158 views

I am writing some Python type stubs for a package, and I have run into a function that can take either a list or, if numpy is available, a numpy.ndarray. If numpy is present and the function is given ...
Isaac E.'s user avatar
0 votes
0 answers
155 views

I am trying to build a descriptor class and want to provide neat type hints to users. The idea is a bit like this: class MyModule(Module): a = Connector(float) b = Connector(Union[float, str, ...
ErikRtvl's user avatar
  • 486
3 votes
2 answers
85 views

Mypy triggers the following error: Incompatible return value type (got "tuple[int | None, ...]", expected "tuple[int | None, int | None, int | None, int | None, int | None, int | None, ...
Marcel Wilson's user avatar
2 votes
4 answers
122 views

Let's say I am writing a catalogue of museum items. Let's say I have a data hierarchy like this (all examples below are pseudo code and not taken from any real project): file baseclasses.py class Item:...
BioLogIn's user avatar
0 votes
0 answers
111 views

I have a class that has a member variable that I want to allow to be any container that implements a few functions, which I'm enforcing with the Protocol below: class RandomAccessContainer(Protocol): ...
David McDermott's user avatar
4 votes
1 answer
136 views

In TypeScript I have Omit, constructing a new type from an existing type by removing keys: interface Todo { title: string; description: string; completed: boolean; createdAt: number; } type ...
julaine's user avatar
  • 2,766
2 votes
1 answer
126 views

I'm using inspect.signature() to get a function signature as a string for generating some documentation by hand, and I'm getting a NameError. I have this minimal Python script to reproduce my problem: ...
Raúl Núñez de Arenas Coronado's user avatar
7 votes
1 answer
170 views

I'm currently working on a library that uses dataclasses.dataclass classes for data structures. I'm utilizing the metadata argument of the dataclasses.field() method to inject custom library ...
JackTheFoxOtter's user avatar

15 30 50 per page
1
2 3 4 5
…
289