4134
Part of @thedevs General Rules: @rulesforthedevs Only related to group topic (Python + Python Frameworks) Other @thedevs groups: https://thedevs.network
Hey guys, I have a silly question for anybody. What’s the difference between decorators and generators in python? Thanks in advance
Читать полностью…
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}")
BadWay is calling DocEnum.__new__
DocEnum._generate_next_value_ # Got from `enum.Enum` :(
IntFlag._generate_next_value_
class DocEnum(enum.IntFlag):
...
DocEnum like this:class Foo(enum.IntEnum, DocEnum):Читать полностью…
...
https://claude.ai/share/c414f6ed-c122-4026-a13a-d598dfd6a9a0
Читать полностью…
i'm getting this error trying to install tikv-client.
Читать полностью…
Okay 👍
But still small many private regulators in are using XBRL format)
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_
_generate_next_value_being None.
Sounds nice. From a casual search, it sounds like "Safety" is an alternative if you want options?
Читать полностью…