StrEnum and IntEnum implies DexEnum, ConEnum, WisEnum, and ChaEnum
@phyphorАй бұрын
Underrated comment!
@ThebiggestgordonАй бұрын
it also implies that we can take a +2 improvement in one of these enums when we get to python 3.12, 3.16, and 3.19!
@Tom_SeekerАй бұрын
Please cover flags next , which are part of enum package . Perhaps you could also enlighten on the meaning of flag boundaries (strict, keep etc.) 😊
@adaum79Ай бұрын
I use StrEnum in my scripts interacting with SAP/R3 to get the component IDs and make the code cleaner
@theglobalsouth9680Ай бұрын
super cool!!! i like the INT ENUMS A LOT
@DrDeuteronАй бұрын
int enums are good as bit wise flags, but after watching this video, I am going to extend normal integer (Z) operations to raise a not implemented error.
@TaleshicMatera19 күн бұрын
The enum module has a dedicated Flag type for bit-wise flags/masks where :D
@МаксимАндреев-я1гАй бұрын
If I need functional of str or int in enum, I make it multiple inheritance like class StrEnumn(str, Enum) or IntEnum(int, Enum)
@tenebrae71111 күн бұрын
I thought it's not possible to inherit from builtins like str, int, slice etc...
@dipeshsamrawat7957Ай бұрын
Thank you 😊
@ChrisHalden007Ай бұрын
Great video. Thanks
@PJutch26 күн бұрын
5:20 I assume that doing it the other way around, like `input() == Role.ADMIN` is more useful
@kellymoses8566Ай бұрын
I created a object to represent Windows file permissions and found the IntFlag enum very useful.
@Madhava_P7Ай бұрын
Excited For Swift!
@mohammadnej7029Ай бұрын
Except the fact that Swift enums are value type, allows you to access both the enum and it’s rawValue simultaneously and so much more ☺️✌️( and don’t need importing)
@deltamicoАй бұрын
So you just saved 4 keystrokes when asking for a value
@MikeMMs07Ай бұрын
Awesome
@asagiai4965Ай бұрын
I think the only thing I like here is the auto function.
@davidgillies620Ай бұрын
The problem is that _enums are not integers or strings_ . It's a mistake to think of enum members as "being" 1, 2, 3 or 'foo', 'bar', 'baz' etc.. They should be opaque and only compared with each other. An enum is supposed to encapsulate a set of related constants and be a first class object in its own right. You should never need to know the underlying value of an enum. If you're mapping HTTP status codes to something, for example, use a dictionary to map the code to an enum value and use that value subsequently.
@asagiai4965Ай бұрын
@@davidgillies620 I didn't say enums are integer or string. But ok I guess.
@eduferreyraokАй бұрын
now I understand how does Django recognize the model field names and use it for query's and such... if you apply auto over the model attrs, BUT i still don't know how does recognize the model class name.
@stroudcuster4483Ай бұрын
StrEnum would be useful when you want to use the enum value as an SQL column value
@balderus6562Ай бұрын
But if Comparisons are bad, what is the advantage of these? Is it just useful with auto()?
@ImKingCosmicАй бұрын
Awesome Sause
@lalropekkhawbungАй бұрын
'Cross-eyed' , ' tongue out ', I wonder why you mentioned that specifically 🤔
@Ak4n0Ай бұрын
Basically an IntEnum is a C enum.
@foxypiratecove37350Ай бұрын
StrEnum is cursed, from a C/C++ & Asm & Machine code developer.
@LuxFerre4242Ай бұрын
Auto everything
@raidensama1511Ай бұрын
Python: nice enums Rust: hold my beer.
@davidgillies620Ай бұрын
Neat syntactic sugar, but it makes code comprehension harder. Enums aren't supposed to be integers or strings; they occupy a separate namespace. Seeing print(role) in a piece of code imposes a higher cognitive load on the reader than print(role.value). Remember: you read code much m,ore often than you write it.
@DelzDerMeisterАй бұрын
If the StrEnum is handled as string when serialising to json, I can see the benefit. "Role.ADMIN" or worse "" is annoying to parse for the receiver. And print(role) just looks like someone forgot to cleanup after debugging
@davidgillies620Ай бұрын
@@DelzDerMeister Serde between JSON and enums is language and implementation-specific. In C++ you'd probably overload >. In Rust you'd implement the Serialize and Deserialize traits. In Go you'd write custom Marshallers and Unmarshallers. It's a recognised issue with a ton of discussion on the web.
@TreyKeownАй бұрын
I agree to an extent, but I think it's fine. Especially coming from the world of C enums, the idea of an enumeration being a value itself is intuitive.
@max_208Ай бұрын
IntEnum and StringEnum are just cursed, just use .value if you want to play around with the value.
@pseudotasukiАй бұрын
These seem contradictory to the concept of enums.
@gurupartapkhalsa6565Ай бұрын
Once you bother implementing StrEnum, it might as well be InstanceEnum. What a short-sighted waste of implementation details
@isaacingleby8771Ай бұрын
After using enums and the match statement in Rust, those features are so disappointing in other languages
@deltamicoАй бұрын
what additional capabilities do they have?
@isaacingleby8771Ай бұрын
@deltamico a lot of it is helped by Rust being a statically typed language, but the match statement assigning values like `let x = match enum_value {...}`. On top of that the match statement can check that you've exhausted all options, so with enums where only a limited set of states are possible, the Rust compiler is clever enough to realise you've left out a possibility and stop compilation from progressing. You can also store distinct objects within different enum values, which is really handy, which means you don't need string enums and int enums, you can just assign branch one a string and branch two an integer if you so wish. It's hard to demo this in a KZbin comment but if you're interested I'd recommend looking up NoBoilerplate's video on enums in Rust.
@stdprocedureАй бұрын
@@deltamico you can do things like struct Cat; struct Dog; enum Animal { Cat(Cat), Dog(Dog), Idk { something: String, }, Other(String), } let animal = Animal::Other("parrot"); match animal { Cat(my_cat) => println!("cat: {my_cat}"), Idk { something } => println!("{something}"), _ => panic!("Crash the program, this should never happen"); } it's mandatory to exhaust every situation, so, either you should use "_" as a "fallback" branch, or you should include all variants (Dog, Other)