python-3.11

sys.getrefcount() returning very large reference counts

sys.getrefcount() returning very large reference counts Question: In CPython 3.11, the following code returns very large reference counts for some objects. It seems to follow pre-cached objects like integers -5 to 256, but CPython 3.10 does not: Python 3.11.2 (tags/v3.11.2:878ead1, Feb 7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" …

Total answers: 1

Type hinting decorator with bounded arguments

Type hinting decorator with bounded arguments Question: An example of what I’d like to do is as follows: @dataclass class Arg1: x = field() @dataclass class Arg2: x = field() @dataclass class Obj: y = field() T = TypeVar("T") R = TypeVar("R", bound=(Arg1 | Arg2)) C = TypeVar("C", bound=Callable[[Self, R], T]) @staticmethod def deco(f: C) …

Total answers: 2

asyncio TaskGroup throwing TypeError when returning lists

asyncio TaskGroup throwing TypeError when returning lists Question: I am trying to use the new TaskGroup object in Python 3.11 to return lists, and I am struggling to find the correct syntax. There isn’t much example code out there yet for this new feature, so I figured I’d ask. import asyncio async def squares(nums): return …

Total answers: 1

How to migrate `shelve` file from Python 3.10 to Python 3.11

How to migrate `shelve` file from Python 3.10 to Python 3.11 Question: Code: with shelve.open("cache") as db: … Python 3.10.9 result A cache.db file is created. Python 3.11.1 result Three files are created: cache.cir, cache.bak, cache.dat. What I need I have important data in the old file and I need to keep using that data …

Total answers: 2

Are Python 3.11 objects as light as slots?

Are Python 3.11 objects as light as slots? Question: After Mark Shannon’s optimisation of Python objects, is a plain object different from an object with slots? I understand that after this optimisation in a normal use case, the objects have no dictionary. Have the new Python objects made it unnecessary to use slots at all? …

Total answers: 1

ImportError: cannot import name 'build_py_2to3' from 'distutils.command.build_py'

ImportError: cannot import name 'build_py_2to3' from 'distutils.command.build_py' Question: I tried to install bipwallet through pip but it says there is no ‘build_py_2to3’ in distutils Defaulting to user installation because normal site-packages is not writeable Collecting bipwallet … Collecting protobuf==3.0.0a3 Using cached protobuf-3.0.0a3.tar.gz (88 kB) Preparing metadata (setup.py) … error error: subprocess-exited-with-error × python setup.py egg_info …

Total answers: 1

How to check if list includes an element using match case?

How to check if list includes an element using match case? Question: I’m trying to check if a single element is in a list using match case. I’m not very familiar with these new keywords so 90% sure I’m using them wrong. Regardless, is there a way to do this? This is my code. I’m …

Total answers: 2

pytest coverage not working after python update to 3.11

pytest coverage not working after python update to 3.11 Question: Issue: pytest stopped generating coverage Description: I upgraded python version from 3.6 to 3.11 (Ubuntu 18.04). I followed this https://www.debugpoint.com/install-python-3-11-ubuntu/ in order to do that. Had issues with pip, followed this advice: https://stackoverflow.com/a/72685573/15923186 I have a project with following structure: test.sh |-sorting |- env (the …

Total answers: 2