2,204,266 questions
Score of 1
2 answers
64 views
Setattr on frozen slotted dataclass raises FrozenInstanceError in py3.13 but TypeError in py3.12
I have the following code:
from dataclasses import dataclass
@dataclass(frozen=True, slots=True)
class Foo:
attr1: int
f = Foo(1)
f.attr2 = 42
In Python 3.13+, I get a FrozenInstanceError, as ...
Score of -6
0 answers
48 views
Does anyone know how images in pyglet work? [closed]
I've been learning how to use pyglet, but I can't understand how the image function works:
pyglet.image.load()
What needs to go in the parentheses, and how do I specify what file this image is taken ...
Score of -5
1 answer
82 views
Google OAuth token exchange gives 401 invalid_client after successful consent
I'm attempting to connect a local Python application to a Google Workspace mailbox using an internal Web application OAuth client, authorization-code flow with PKCE, and a loopback callback. Consent ...
Score of -3
0 answers
44 views
Why does scikit-image skeletonization produce off-center loops and unwanted branches in thresholded handwritten strokes?
I'm developing a handwriting-to-plotter application. I need to convert scanned handwritten text into one-pixel-wide centerlines and then trace those centerlines into coordinate polylines.
My problem ...
Score of -6
0 answers
164 views
Can ast be used to parse a single line? [closed]
Is it possible to use ast to parse a single line?
At the moment this falls over because of the white-space at the start of the line. Obviously I can strip this out but it will then be missing when I ...
Score of 1
0 answers
96 views
How to make a generic type that accepts Ellipsis like tuple[int, ...]
As noted in this answer and this docs, Python's builtin tuple supports Ellipsis (...) in generic annotations. For example, the following denotes a variable-length homogenous tuple of ints:
tuple[int, ....
Score of 3
1 answer
101 views
Why does ContextVar return its default value inside run_in_executor() in Python asyncio?
I'm working on an asynchronous Python application where I use ContextVar to store request-specific information, such as a request ID. This allows me to access the current request ID from different ...
Score of 3
1 answer
90 views
Compare lists in one column to the first n elements of another column in Python Polars lazyframes, where n is dynamically determined from index
I'm trying to compare words present within sentences in one column, to the first n words in a wordlist (in another column), and return the words in the sentences that don't exist in that subset of the ...
Score of -5
0 answers
93 views
Changing WSGI app makes SQLite file unable to be found
I am trying to move from a prepackaged Flask/uWSGI to a custom Docker with Gunicorn. My Dockerfile is changed into:
FROM python:3.13-slim
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
...
Score of 1
2 answers
151 views
Should module-level constants in constants.py be annotated with typing.Final
According to this Q&A, Python constants are written in uppercase by convention and can be annotated with the Final qualifier.
From the typing docs:
typing.Final
Special typing construct to ...
Score of 0
1 answer
142 views
Making a bar chart with varying values along the y-axis
I'm trying to make a bar chart showing pinned/unpinned vortices depending on tilt. Because of this, I want each bar to represent one vortex, and the y-axis to be the tilt. Currently I have this code, ...
Score of -5
0 answers
85 views
Moving from legacy docker / uWSGI / Flask to new best practice
Years ago (2015-2020) I created a few hobby projects. The setup was extremely simple via:
tiangolo/uwsgi-nginx-flask:latest docker image, a slim docker image with a production ready webserver
simple ...
Score of 1
1 answer
212 views
Why can a parameterized class be instantiated?
I have this generic class:
class Box[T]:
def __init__(self, val: T):
self.val = val
In Python <3.12, that would be written:
from typing import TypeVar, Generic
T = TypeVar('T')
class ...
Score of 0
2 answers
135 views
Python API returns 8 and 22 instead of dates and symbols when selecting individual columns
I query a DFS table from Python. select * gives me correct dates and tickers, but as soon as I list the columns, TIME turns into 8 and CODE turns into 22 — the numeric columns are fine.
raw = session....
Score of 3
2 answers
147 views
Difference between three forms of instantiating a generic class in Python
I have this generic class in Python 3.12:
class Box[T]:
def __init__(self, val: T):
self.val = val
I can instantiate it in 3 ways:
box: Box[int] = Box(42)
box = Box[int](42)
box = Box(...