thedevs_python | Unsorted

Telegram-канал thedevs_python - Python

4134

Part of @thedevs General Rules: @rulesforthedevs Only related to group topic (Python + Python Frameworks) Other @thedevs groups: https://thedevs.network

Subscribe to a channel

Python

Hey guys, I have a silly question for anybody. What’s the difference between decorators and generators in python? Thanks in advance

Читать полностью…

Python

Hey, I have the following code:

https://termbin.com/t46m

#!/usr/bin/env python
import enum


@enum.unique
class DocEnum(enum.Enum):
"""
An enum that lets you optionally specify a docstring for the enum variants.

Examples
--------
>>> import enum
>>>
>>> class MyFlags(enum.IntEnum, DocEnum):
>>> Foo = enum.auto(), "Foo oparg"
>>> Bar = enum.auto()
>>> Baz = enum.auto(), ["can", "be", "anything", "really"]
>>>
>>> MyFlags.Foo.__doc__
Foo oparg
>>> MyFlags.Bar.__doc__ is None
True
>>> MyFlags.Baz.__doc__
['can', 'be', 'anything', 'really']
"""

def __new__(cls, value: int, doc: str | None = None):
obj = int.__new__(cls, value)
obj._value_ = value
obj.__doc__ = doc
return obj


class BadWay(enum.IntFlag, DocEnum):
Up = enum.auto(), "Up"
Down = enum.auto(), "Down"
Left = enum.auto(), "Left" # This is "dropped"
Right = enum.auto(), "Right"


class GoodWay(enum.IntFlag, DocEnum):
# Ideally this get set automaticly
_generate_next_value_ = enum.IntFlag._generate_next_value_

Up = enum.auto(), "Up"
Down = enum.auto(), "Down"
Left = enum.auto(), "Left"
Right = enum.auto(), "Right"


print("BadWay")
for member in BadWay:
# Up = 1
# Down = 2
# Right = 4
print(f"{member.name} = {member.value}")

print("GoodWay")
for member in GoodWay:
# Up = 1
# Down = 2
# Left = 4
# Right = 8
print(f"{member.name} = {member.value}")


The good news, is that BadWay is calling

DocEnum.__new__

The bad news are that it also uses:

DocEnum._generate_next_value_ # Got from `enum.Enum` :(

If someone have an idea on how to make it so it will use:
IntFlag._generate_next_value_

It would be great :)

---

Unfortunately, I can't do something like:

class DocEnum(enum.IntFlag):
...

Because there are other classes that inherent DocEnum like this:

class Foo(enum.IntEnum, DocEnum):
...

Читать полностью…

Python

♻️ ‎POURIA 🦋 unbanned ‎Sex expert [971182497].

Читать полностью…

Python

https://claude.ai/share/c414f6ed-c122-4026-a13a-d598dfd6a9a0

Читать полностью…

Python

i'm getting this error trying to install tikv-client.

Читать полностью…

Python

Okay 👍
But still small many private regulators in are using XBRL format)

Читать полностью…

Python

I have tried to play with the MRO and __init_subclasses__ but that didn't really worked out as __new__ is called before (from what I saw)


Tried to do something like:

class DocEnum:
...

del DocEnum._generate_next_value_

but then I got errors about
_generate_next_value_
being None.
I guess that the MRO map is built on inheritance. I ain't that familiar with it

Читать полностью…

Python

There's a joke waiting to happen here…

Читать полностью…

Python

Just following the docs

Читать полностью…

Python

why are you using test.pypi.org ?

Читать полностью…

Python

Sounds nice. From a casual search, it sounds like "Safety" is an alternative if you want options?

Читать полностью…
Subscribe to a channel