#internals-and-peps
1 messages · Page 77 of 1
you're writing a meeting application, and you want to allow the user to schedule a meeting. The user wants to schedule the meeting for 9 AM next Thursday. You can't do that using only UTC.
no timezone works when it works... until it doesn't and you hate life for a weekend
you're writing a meeting application, and you want to allow the user to schedule a meeting. The user wants to schedule the meeting for 9 AM next Thursday. You can't do that using only UTC.
@raven ridge Does that sort of thing get written solely in Python?
or scheduling a meeting with folks in another timezone
Python is everywhere, doing everything
Sure, absolutely.
Only time I've worked with input dates like that they came from the web and I let JS do the conversion
what did you let it convert to?
UTC
that's wrong.
the user's UTC offset can change between when they schedule the meeting and when the meeting time that they scheduled occurs, and now you're off by an hour.
they get the alarm an hour too late, and you have angry users.
no - that's why using it is wrong.
If I send out a message at X UTC time that will be the correct time whatever the users timezone.
Right. But the user's meeting isn't scheduled in UTC. It's scheduled in an actual timezone.
You convert the user selected datetime to the UTC time. Do everything in UTC after that
so if you send out the message at some UTC time, and the UTC time that you send it out at no longer represents the time in the user's timezone when it should have been sent out, you've done the wrong thing.
But then you converted the datetime wrong in the first place...
Right. But the user's meeting isn't scheduled in UTC. It's scheduled in an actual timezone.
@raven ridge but you can compare the two, since they're both timezone-aware
not if you don't store a timezone identifier, you can't.
it doesn't matter what timezone the user's meeting is scheduled in, as long as the two refer to the same absolute time
not if you don't store a timezone identifier, you can't.
@raven ridge why wouldn't you?
If they say - I want a meeting on X date at Y time in Z tz and you convert that to the UTC time
there's no way to get from a UTC time back to the time the user originally entered.
Then you trigger at the UTC time you stored. You'll be right
Unless somehow the definition of that timezone changes between the two events
like the point is that you are storing timezone-aware datetime objects (or the equivalent), right
not if their offset rules change in between when the scheduling happened and when the meeting happens.
not if their offset rules change in between when the scheduling happened and when the meeting happens.
@raven ridge Only if the offset rules about that date change
In that case though you're going to break unless your timezone info has been updated anyway...
sure - but timezone databases get updated every week.
and people schedule meetings for more than a month out.
UTC is appropriate for storing events that have already happened, because past offset rules are frozen. It's appropriate for storing astronomical events, because the time at which a comet passes us is a fixed point in UTC. They're not appropriate for representing future events in the time used by human beings, because the rules can change after they're stored and before the event occurs.
Theres a nice video from computerphile about the nightmare of dealing with timezones
A web app that works out how many seconds ago something happened. How hard can coding that be? Tom Scott explains how time twists and turns like a twisty-turny thing. It's not to be trifled with!
A Universe of Triangles: http://www.youtube.com/watch?v=KdyvizaygyY
LZ Compressi...
Thats the one
was just about to paste
i watched this video, and immediately forgot everything and vowed to never try to understand all this time crap
Haiti changed their rules with less than 2 days notice only 2 years ago. This is a real life actual problem that software needs to deal with.
and then there's leap seconds!
that's actually a proposed solution
just don't give a crap if the sun is directly overhead at 1200
I'd never had to think about the future timezone problem because I don't deal with future events. But that has really fucked me up
getting rid of timezones doesn't really help. It probably causes more trouble than it solves. A more practical solution would be removing politics from timezones, removing summer time transitions, and making it so that every place on earth is at the same UTC offset year round and will be forever - preferably tied to latitude and longitude rather than national borders.
That seems worse than removing timezones
getting rid of timezones doesn't really help. It probably causes more trouble than it solves. A more practical solution would be removing politics from timezones, removing summer time transitions, and making it so that every place on earth is at the same UTC offset year round and will be forever - preferably tied to latitude and longitude rather than national borders.
@raven ridge not sure if that's practical
in the sense of practically likely to happen
Under that system you would end up with countries having weird timezone enclaves/exclabes
not sure if that's practical
Oh, it's certainly not practical, but it's what I would take as my ideal if we could get everybody on board to pick one system and stick to it.
Getting rid of timezones entirely isn't practical, either.
🙂
indeed it is not
How is that more practical though?
after the AI wars we won't be able to see the sun anyway
I'm still not sure I see any particular issue with removing timezones
might as well all use UTC
@safe hedge give https://qntm.org/abolish a read
I think the influence of politics (and business, and history) is way too strong in this regard for either of those to happen inthe near future, anyway
I mean perhaps it's because I'm British so our time wouldn't change. But the first one doesn't really seem an issue to me
You already have to know how far ahead/behind countries are anyway
I live many timezones away now and I just operate on a "are we overlapping" basis if I need to interact with my folks
You get used to it pretty quick
read the whole essay. It's really good, and will give you a much more nuanced view of the topic.
The solar day issue is definitely more of a problem
Does anyone have any good resources for learning regex? I'm working on a parser for a joke file type I made.
I learned rather abruptly that I'm not familiar with regex
oh sorry
it's solving different problems
Yeah we had this discussion the other day I think
pypy is an implementation of python
Cython is a language superset used to write code which is compiled to provide speed benefits.
I'm not going to say anymore because my grasp on Cython is limited as hell and there will be people in here who can explain it better
Cython can be faster than pypy if you use enough C things there
it can also be slower since there is some cost of running converting to C
pyx files are compiled during the project build
I meant converting the runtime representations of python objects to things C can operate on.
there's no conversion tho, the PyObject* gets passed and it's handled directly by the interpreter
just like with builtins and most stdlib modules
well, as far as I understand, for something like
cdef int x = 7
for n in range(x):
some_external_lib.function(n)
```it has to convert n to a python int object some that the external lib can use it. PyPy does not have this overhead
say i modify a single file from the cpython source code and i want to test my changes. how would i build that file and add it into the executable without building the whole cpython again?
you can't
damn
best case scenario is the file in question is part of a dynamic lib and you only have to build the library
You can build it again and put it early in the python path, and the library should import it
has anyone here developed any desktop apps using python?
what's all the clinic stuff?
@true hollow you mean https://docs.python.org/3/howto/clinic.html?
okay so i got it how to build a single thing instead of everything
just run make without running before make clean
anddd
why am i getting this ```py
atie()
Hello! - this post was made by the atie gang
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
SystemError: <built-in function atie> returned NULL without setting an error
ah
i need to simply put at the end Py_RETURN_NONE
who will tell me to get binary data of any type of file in python or somewhere else
@safe oracle can you help me with this python problem
this is not a help channel, see #❓|how-to-get-help @warped hamlet
@sacred yew sorry
Hello
@manic hatch Hi, what's your favorite PEP?
but pep 8 didn't introduce a new feature
Yeah it works more on formatting
Can you help me round of a float to a 6 digit float
Like I want 0.5 to 0.5000000
this isn't a help channel, but you read #❓|how-to-get-help to learn how to open one. I'll check to see when you do.
@boreal umbra #help-lollipop
My favorite not-yet-implemented PEP is perhaps 505
I know a lot of people want that but I'm not sure if I'd use it.
anyone know how I could add the coding necessary to make a SAPI5 text-to-speech voice speak new symbols? (I'm trying to help blind people).
I think maybe I can set up some kind of NLP library which includes the other symbols, right? perhaps it could include groups of symbols to speak them differently as well.
@violet jetty wow, that's a really advanced and IMO worthwhile exercise.
Speech to text for mathematical formulas is an amazing project
I just had an idea. Maybe some kind of Stephen Hawkng society knows how this can be done? He was disabled...
If you listen to this, there's a lot missing. You're going to have a hell of a time understanding this stuff if you can't see.
@unkempt rock Don't bump your help channel in other channels. The topic of this channel is stated in its description.
oh sry i ll delete the mess
only dict keys must be hashable, am i right?
Not only, but yes, they have to be hashable
i'm saying that on a hashmap context, like, doesn't matter if the value of this key is hashable or not
i understood this by reading and making some tests and just want to assert that
okay, thanks :D
I'm fairly confident in saying that any object in Python can be a value in a dictionary
does anyone know of a library/package to validate emails and their MX? every package seems to fail miserably at it
:incoming_envelope: :ok_hand: applied mute to @loud hare until 2020-10-08 16:29 (9 minutes and 58 seconds) (reason: duplicates rule: sent 4 duplicated messages in 10s).
:incoming_envelope: :ok_hand: applied mute to @old axle until 2020-10-08 16:29 (9 minutes and 59 seconds) (reason: duplicates rule: sent 5 duplicated messages in 10s).
<@&267629731250176001> they spread to other channels
yes
yes to the runtime exception when you try to us something that isn't implementing what ABC says it needs
and Protocols is like that, but with static analysis
@sacred tinsel ```py
x = {}
x['key'] = NotAValue()
print(x)
Don't use <NotAValue id:140571922572144> as a value!
{}
^ made a class that cant be used as a dictionary value
this is so sad I guess im going to have to pay to validate email addresses
🤔
@pliant tusk that's just overloading str isn't it
for pretty much every single python library, you can type in anything@anything.com, ask to check MX, and it won't work
Oh wait no I can't read
str would work if it was only removed when printed
>>> x = {}
>>> x['key'] = NotAValue()
>>> 1 + 1
Don't use <NotAValue id:140304704512880> as a value!
2
>>> x
{}
>>> ``` but this works too
currently it also cant be stored like var = NotAValue() because i havent added globals detection yet
>>> x = (NotAValue(),)
>>> print(x)
(<NULL>,)
>>> print(x[0])
[1] 81135 segmentation fault python3``` now i may have gone a bit overboard
anyone know sentence probabilities here ?
I want to make a program that sorts pictures into categories. For example it can tell if the picture is a cat, dog, human, or car and if it cannot tell what it is it puts it in another folder where the user can tell what it is. Any clue as to where I could start?
@uncut sun , I think you should ask the Tensorflow Magicians at #data-science-and-ml
@violet jetty could replace the symbols with words
Why the REPL header is written into stderr, rather than in stdout?
https://github.com/python/cpython/blob/bfe6e03cd6931813dd61b50f5fdf7d8a8848f4cd/Modules/main.c#L195
maybe so it's a different color
That makes no sense lol

i don't know as you can probably tell
you mean why is the python version etc?
didnt look at the link
click the link
it's the code where Python 3.10a+1 (build Oct 8 bla bla bla) is printed
and for some reason
it's printed into stderr
which makes no sense
because the header isn't an error or something
ye
but yeah different colour and separation from output would be my guess
i don't know though
@true hollow this is so that you correctly pipe it into other programs
notice how the 3. in GCC 9.3.0 and Python 3.8.2 don't get highlighted by grep
but the output from evaluating math.pi does
only the result of expressions and print (or any other explicit write to stdout) get passed to stdout
Yeah, stderr isn't always used for "errors", sometimes it's just used for "other". The prompts printing on stderr is pretty interesting, though.
The banner doesn't surprise me, but the prompts do.
i was thinking that's the point but like
why is that useful
-c "<code>" wouldn't need it
i want to make my bot status be smthn like: "Watching 263 Guilds & 38283 Members" but i get an error, someone said i have to loop the guilds but idk how. can someone help
the guild count works, but not member count
Guilds | (len(guild.members)) Members)", type=discord.ActivityType.watching))```
@unkempt rock This is not a help channel, read the channel description. See #❓|how-to-get-help or #discord-bots
I'd suggest using #❓|how-to-get-help
Please read channel descriptions before posting.
anone who can make a botnet with python sockets
@paper merlin wrong channel, this is for language discussion. try #❓|how-to-get-help.
ok
@feral stone https://www.python.org/dev/peps/pep-0634/
Interesting, interesting.
do you use functional languages?
I can't remember which ones could be considered as such but I use a few.
Not just Python.
Namely Assembly, some Lua, a very small amount of CSS.
No to all of those.
are you familiar with the term?
It's been a while so it's not as familiar to me right now.
oh, okay
so basically it's a programming paradigm that revolves around, among other things, functions as first-class values that tend to be pure
anyway, the point I wanted to bring up was
you originally talked about switch, like in C, which is basically a restricted if
the pattern matching referred to in the PEP is kind of like a more advanced form of that, and it's common in functional languages
That sounds like it could accomplish a similar task.
hello
Ideally I would want it to be something official that lightens the need for many nested if statements.
For efficiency.
who is the person who know python well please help I will share screen with him
is there anyone
Or rather, a way to perform the same task, but in a less open and computationally-expensive way.
who is the person who know python well please help I will share screen with him
@ivory cosmos #❓|how-to-get-help
Ideally I would want it to be something official that lightens the need for many nested if statements.
@feral stone yup, it looks like it'll make it into 3.10
just an example from a different language:
scala> def resolve(pair: Pair) = pair match {
| case Pair(0, 0) => "origin"
| case Pair(_, 0) => "x-intercept"
| case Pair(0, _) => "y-intercept"
| case Pair(x, y) => s"just a point ($x, $y)"
| }
no help does not work
@ivory cosmos also, this is not the right channel. this is a channel for language discussion
By the way, if class patterns are a thing, would something like this be conceivably possible?
Point(x, y) = p
@feral stone yup, it looks like it'll make it into 3.10
@gleaming rover ah, really? Last I heard the proposal was still very contentious and the steering council wasn't very close to agreement on it.
@gleaming rover ah, really? Last I heard the proposal was still very contentious and the steering council wasn't very close to agreement on it.
@raven ridge no, you are right
what I meant to say was that the earliest it looks like it'll make into is 3.10
since 3.9 just got released
thanks for clarifying
and probably not even then.
There's a good reason for that, beyond just a lack of consensus: 3.9 includes the new PEG parser and the old parser, and a command line switch to fall back to the old parser. So, it can't contain any syntax that the old parser can't support.
yup, that's a good observation too
The LL(1) parser is still the default in 3.9
That's not what the release notes say.
Starting with Python 3.9 alpha 6, include the new PEG-based parser machinery in CPython with a command-line flag and environment variable that allows switching between the new and the old parsers together with explicit APIs that allow invoking the new and the old parsers independently. At this step, all Python APIs like ast.parse and compile will use the parser set by the flags or the environment variable and the default parser will be the new PEG-based parser.
Right, I looked it up before alpha 6, my bad
Why the builtin function's first parameter is the module/self? (c code)
i made a builtin with no parameters and it just worked fine
I’m guessing for consistency sake they use it in every functions, while the API is smart enough to not error out if you don’t actually use it
Also every builtins are objects, so they have a self-reference because of the object method
@true hollow how did you register your function? builtin_next is https://docs.python.org/3/c-api/structures.html#METH_FASTCALL
I just thought ```python
@inline
def identity(something: T) -> T:
return something
@apply_inline
def main() -> None:
variable = 42
same_variable = identity(variable)``` and main() gets bytecode updated to inline identity() call
I don’t think an inline call really matters for CPython
I have written a (de)serialization library for on project and trust me, function calls are expensive
Is that your 1 million recursion limit project haha
nah
haha
https://github.com/nekitdev/gd.py/blob/develop/gd/model_backend.py I wrote this for parsing data of the game, with models defined in https://github.com/nekitdev/gd.py/blob/develop/gd/model.py.
I literally have functions that do small processing, then call std function — and by inlining I could reduce amount of function calls to a half the current number
@cloud crypt this is a veeery old issue, (10 years old) but it might be interesting to check it out: https://bugs.python.org/issue10399
i made a builtin with no parameters and it just worked fine
@true hollow https://stackoverflow.com/questions/27324010/why-does-passing-extra-arguments-to-a-c-function-does-not-result-in-a-compile-ti
The interpreter will pass you the arguments anyway. That just happens to work.
It's undefined behavior, but happens to have worked fine for you. You shouldn't rely on it, and should instead declare your function as talking the appropriate number of arguments for the type you register it as, even if you won't be using them.
Why can i not run a discord bot and a twitch bot at the sane time?
i have them both in the same document but doesnt seem to work
Hey @solemn topaz you should take a look at #❓|how-to-get-help
i have asked there but havent gotten an answare in 1 hour
@undone hare never got help so it closed it self LUL
Well, this is still not an help channel
How does hashing work? It's able to take in data of any size and change it to a fixed size, and I'm really curious.
a hash is simply a function from some type t to int (or string), it doesn't necessarily make it smaller, depending on what you use your hashes for, you may want to go for certain properties
What kind of hashing? The one python uses for its objects or things like SHA?
Neither of those are able to represent arbitrary amount of data since that is impossible without unlimited size for the hash result
It doesn't exactly make the data smaller, it just generates a value such that equal items will have equal hashes
SHA, really. (That is all i've worked with)
the hash algorithms in the SHA family are "cryptographic hashes", the most important property such functions need is that it must be impossible (ideally) to invert, as for the implementation itself, it really isn't anything complex, the impressive part imo is creating such hash functions, you can look at the papers describing them and implement them in a few hundred lines of code easily
important note is that hash in python is not meant to be a cryptographic hash
An hash in itself is mean to map an arbitrary length input to a fixed length and content output
If you talk about a cryptographic secure hash, the operation shouldn't be easily reversable
Note that by reversable I mean that you can easily generate an input that will yield said output
A very simple numerical hash which create output under 4 characters could be a simple lambda n: n % 9999 for example, but obviously it is very trivial to generate a number that will yield 3567 for instance
what's the file in the cpython repository that executes the bytecode? i am trying to make a new keyword that simply prints something and it isn't working. i modified the grammar file, the syntax file, the ast, the pgen, the compile.c file, the parser and everything and it doesn't print anything
ceval.c
yeah, a bit scary
basically it is a big switch/case (technically not for some cases, but that is the easiest way to explain it), so you have to find some spot after TARGET() macros and register your opcode over there
with looking other opcodes and how they operate on the stack
ah okay
hm, there is an opcode_targets.h file
should i do something to it beforehand?
yeah
There are empty fields
fill one of them with something like &&TARGET_BINARY_TORANGE
i remember setting Atie_kind to 26 in some struct in Python-ast.h
actually, that is an auto-generated file
ah
you need to make changes on the Parser/Python.asdl
i did
in the line that was like Break | Pass, i appended | Atie
i basically made a pass replica
in the line that was like
Break | Pass, i appended| Atie
@true hollow looks good
sorry if i sound so noob 😅
i never expected cpython be soo complicated
I can actually send a link to you about a total patch that implements @ operator
it goes through all the phases
like opcode_targets.h ceval.c asdl etc
but first, I need to find it
yeah, it would be great if you sent it
could help me a lot
i found an answer in a stackoverflow thread on how to make a new statement but it was outdated
so, i had to figure it out all by myself
yeah, new parser changed alot
like, imitating pass, using the search function on github, reading a pep that was 339?
Commit d51374ed78a3e3145911a16cdf3b9b84b3ba7d15
this is also extremely outdated for parsing etc but can show you the remaining steps
Also, when you changed ASDL or grammar / opcode files, you can use make regen-all to regenerate everything
thanks!
hi
so i have been trying to run the snake game but im getting this error
what is the problem here
oh
i just use python.orgs idle
There could be answers on StackOverflow
I've had errors like that
Like "Append is not supported"
I've never been able to fix them
tbh I gave up making a new keyword
I will try again later when I've studied cpython more deeply
Goodmorning everyone.
You guys should look into Blockchain, its in its rock age, we rarily even know what it really is for now.
But the possibilities are endless
Are we on LinkedIn now ?
I'm in the camp that insertion order shouldn't have been added to the spec for dicts, but we do have OrderedDict. I think they should have sortkeys and sortvalues methods
thoughts?
I recall it was just a side effect of a better underlying implementation, so there's almost no cost to it
that doesn't necessarily justify it being in the spec though
my objection is to adding it to the spec
adding it to the spec has a cost tho, it means future implementations can't not have that property without being backward incompatible
@boreal umbra what's your reasoning against?
i'm guessing what i just said
There might be one, but I'm yet to see a situation where relying on the insertion order of a dict is actually using it as an efficient lookup system.
Often these situations seem to be treating the dict as lists of tuples
I've come across situations where it was convenient, but the lookups could have been done by position instead, that is true
I'm guilty of this myself by the way, I had something that needed to be a dict during an earlier stage and then I converted it to an ordered dict and iterated over it
that's basically my usecase, yes oh it's not, I misread
it's hardly the worst possible coding practice, but I think it misses the point just enough that it shouldn't be part of the spec.
on the other hand, if it isn't in the language spec, you may not be allowed to make use of it for serious projects
if there's a case where you need the insertion order as it occurred organically during the run of the code (and not according to some intentional sort after the fact), I guess it's nice that people have that.
The discussion for it is here https://mail.python.org/archives/list/python-dev@python.org/thread/4AK2N6X5MIBT6PA4PGDZH5XGDOT67K7S, it looks like the maintainers of other major implementations either didn't mind the change or already had dicts implemented with order
but I would argue then that we already had OrderedDict in the stdlib, so restricting the spec of regular dict just paints us into a corner.
but I would argue then that we already had OrderedDict in the stdlib, so restricting the spec of regular dict just paints us into a corner.
@boreal umbra I still don't get the argument, 'ordereddict's has nothing to do with 'dicts that preserves insertion orders'
@true ridge sorry, I don't think I understand what you mean
why should we restrict future implementations to preserve order of insertion
I mean that,
I would argue then that we already had OrderedDict in the stdlib
This argument is not relevant with dict's now preserving insertion order
OrderedDict's are still useful, when they needed.
it is, if someone wants an order-preserving dict, they can use OrderedDict, they don't need to rely on dict's implementation details
Depends on the use case, yes
my argument is that since OrderedDict is already part of the standard library, and anyone with Python installed can use it when they want preserved insertion order, future versions of the language shouldn't be required to do that for the standard dict class.
If you really 'care' about the insertion order, then you would probably prefer OrderedDict over dict for cases like below;
>>> {'x': 'y', 'y': 'z'} == {'y': 'z', 'x': 'y'}
True
>>> OrderedDict({'x': 'y', 'y': 'z'}) == OrderedDict({'y': 'z', 'x': 'y'})
False
but, for majority of use cases that, I personally use 'dict' when the ordering is needed. I don't need to do extensive work with it.
I don't know if there will ever be a time when the core devs have to say "it would be a lot easier to switch to this better implementation if we didn't have to preserve insertion order"; in fact I think it's unlikely.
but I don't know very much about the cpython internals
but it sounds like going forward, insertion order is still the only ordered property that regular dicts will have
adding it to the spec basically froze the implementation of dict, even if it would have taken 30 years for it to change, I can still see people will complain about it at some point
so my thinking is that they should have in-place sort methods.
though I'd prefer to have function composition
(OrderedDict @ sorted)(<some generator expression>) would be pretty good.
one can always dream :p
the trick would just be if one of the operands for @ isn't specifically a function (as opposed to any callable) or a class.
because then it might try to use the __matmul__ method of that object and throw the whole thing off.
we had a discussion about this here in the past, and got stuck on the same point
not sure if that was with you or someone else
i'd love to have __matmul__ be defined as function composition, but you run into a big mess if you want to compose something that implements both __matmul__ and __call__
so i guess we'd need another binary operator for composition, or maybe better yet a keyword like or/and/not that gets handled directly by python
yes, you'd basically have to do something like (MyClass.__call__ @ sorted), I think
would you also have to do it for init?
hm.
actually that wouldn't even work
what if type(OrderedDict) has __matmul__
because if you call init directly then a new object doesn't get made
ah true it'd be __new__?
not sure if that would call __init__ though
actually i'm not sure how that works. what's the "functional" version of class instantiation?
I thought that all happened in type.__call__
probably
keep in mind, MyClass.__call__ is an instance method in this context. at least that's what I think it is.
so it relies on the item being passed to it belonging to that class
but I think it would circumvent calling a function named __matmul__
so MyClass.__call__ is a function
and then it's in a chain with some @ operators
what does __ do
so it's MyClass.__call__.__matmul__ that gets called to do the function composition
two underscores on either side just indicates that it's part of the language in some way
yeah, that's fine
what i'm talking about is your previous example
there's still ambiguity if type(OrderedDict) for some reason implements __matmul__
that would return type, yes?
so someone might have already subclassed type and implemented matmul for it?
couldn't you get the same unexpected behavior if someone subclasses dict and overrides __or__?
(given 3.9)
sure
but | is just... "or"
@ to mean function composition would be such a leaky abstraction
since it's already mis-appropriating the matmul operator
@paper echo in what way is it mis appropriating it?
they have different incompatible semantic meanings
and they're much more likely to clash than, say, the overridden binary operators used by numpy and pandas
@ was used for decorators first and that's already a composition like operation
true, but im talking about times where the actual behavior of the @ binary operator is unpredictable and potentially very confusing
some people thought they needed @ to mean matrix multiplication, so here we are
believe me, i'd much rather it used for composition
Would it really be confusing in a way that other issues with dynamic typing aren't confusing though?
Unblessed uses of operators can still be effective. The division operator is used for path joining in pathlib.
Let's not forget the fact that string modulo as formatting is somehow commonly accepted
@radiant garden seems like that's now the least popular way to do string formatting, but it does fall into the atypical operator usage I'm thinking of.
If only python wouldn't have continued the C mistake of allowing operators not separated by space... Then operators could easily be user defined as common words. Plus we could have had kebab-case :(
What's the difference between Python/ast.c and Python/Python-ast.c?
@half wolf sounds like it's time to start using Hy
What's the difference between Python/ast.c and Python/Python-ast.c?
@true hollow for 3.10,Python/ast.ccontains only the verifier for user-defined ASTs
the Python/Python-ast.c contains all nodes for _ast and the conversion between the AST that the interpreter uses and the AST that is exposed to the python level with _ast module
for 3.9<, the Python/ast.c was used both for the verifier and the CST to AST transformation
note that, the Python-ast.c file is fully auto-generated, but on the other hand ast.c is hand written
Hey guys, qucik question, I know asyncio has a "get_event_loop" but does multi threating have anything like that? Or how would I get that with threating?
@vapid slate this is a discussion channel; try asking in #async-and-concurrency
Got a nooby conceptual question. If I make a module (let's say moduleB) to use to communicate with other module (let's say moduleA), can I call moduleB an API?
What do you people think?
Well, the interface that module A uses to call module B is the API.
So the public function signatures, classes and variables, etc.
The implementations are not part of the API.
@gloomy rain
I was wondering if it is possible to implement a for loop in python without the use of for and while. Assembly has the jmp instructions to move the instruction pointer, which you can use to make a for loop. But that doesn't exist in python, I then realized goto is nearly the same as jmp which is in C/C++, so I searched if it was possible to implement goto in python. And apparently you can, https://github.com/snoack/python-goto. But I started looking at the source code to see how this goto was implemented and went off track from the actual question of implementing a for loop. I have to go right now, but if I could get any ideas on how to do this, or if it is even possible in the first place would be helpful
you could do it by crafting bytecode using something like hax
@unkempt rock You can replace any loop with recursion, but that has a limit
You can also do
[*map(something, something_else)]
if you just want to avoid the words for and while
Is there any way to identify how the app was made? Im trying to recreate app from “ABOUT YOU” for my personal project to add to my resume
what is this register method
import ipaddress
import abc
import six
@six.add_metaclass(abc.ABCMeta)
class IPv4v6Base(object):
"""Metaclass providing a common base class for the two scalar IP types."""
pass
IPv4v6Base.register(ipaddress.IPv4Address)
IPv4v6Base.register(ipaddress.IPv6Address)
@swift imp i believe it sets the metaclass of ipaddress.IPv4Address to be IPv4v6Base
!d g abc.ABCMeta
class abc.ABCMeta```
Metaclass for defining Abstract Base Classes (ABCs).
Use this metaclass to create an ABC. An ABC can be subclassed directly, and then acts as a mix-in class. You can also register unrelated concrete classes (even built-in classes) and unrelated ABCs as “virtual subclasses” – these and their descendants will be considered subclasses of the registering ABC by the built-in [`issubclass()`](functions.html#issubclass "issubclass") function, but the registering ABC won’t show up in their MRO (Method Resolution Order) nor will method implementations defined by the registering ABC be callable (not even via [`super()`](functions.html#super "super")). [1](#id2)
Classes created with a metaclass of [`ABCMeta`](#abc.ABCMeta "abc.ABCMeta") have the following method:
`register`(*subclass*) Register *subclass* as a “virtual subclass” of this ABC. For example:... [read more](https://docs.python.org/3/library/abc.html#abc.ABCMeta)
So I wasn't quite right
Not sure what it does now after reading the docs... not a great explanation in there
Does the CI in the cpython repo really takes so long? isidentical made a push 3 hours ago and the circle is still yellow
depends on what actions they setup
2 In progress
44 successful
4 skipped
8 pending checks
they're litterally running through everything and checking coverage of code so yes its gonna take a while
?tag IndexError
Per PyDis' Rule 5, we are unable to assist with questions related to youtube-dl, commonly used by Discord bots to stream audio, as its use violates YouTube's Terms of Service.
For reference, this usage is covered by the following clauses in YouTube's TOS, as of 2019-07-22:
The following restrictions apply to your use of the Service. You are not allowed to:
1. access, reproduce, download, distribute, transmit, broadcast, display, sell, license, alter, modify or otherwise use any part of the Service or any Content except: (a) as specifically permitted by the Service; (b) with prior written permission from YouTube and, if applicable, the respective rights holders; or (c) as permitted by applicable law;
3. access the Service using any automated means (such as robots, botnets or scrapers) except: (a) in the case of public search engines, in accordance with YouTube’s robots.txt file; (b) with YouTube’s prior written permission; or (c) as permitted by applicable law;
9. use the Service to view or listen to Content other than for personal, non-commercial use (for example, you may not publicly screen videos or stream music from the Service)
@swift imp @paper echo lets you do isinstance when you dont control the subclass's code
so the class you register comes back as True when doing isinstance(registered_class, abcMeta_class?
isinstance(registered,IPv4v6Base)
Thanks
so it makes isinstance work without the registered class actually inheriting other metaclass behavior
Just curious about something, would None-aware operators have an impact on performance?
https://www.python.org/dev/peps/pep-0505/
Hm, no? They're new operators, so if you don't use them you shouldn't pay any costs for them, barring the minor increase in work that the compiler has to do to parse code that might or might not contain them.
anyone interested in group study for prep coding interviews?
And if you do use the operators, I'd expect them to be as fast or faster than the equivalent version that uses an if statement.
ah, right
yeah
k,j
Does anyone know what __basicsize__ is?
It's related to this: https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_basicsize
I don't think it's typically something you'd concern yourself with, but I'm not sure
Where are PyNumber_And and PyNumber_InPlaceAnd defined? I used the GitHub search function and I couldn't find their definitions
It's defined with a macro here:
which calls binary_op1 here: https://github.com/python/cpython/blob/037245c5ac46c3436f617a1f5d965929754be239/Objects/abstract.c#L775
Which calls NB_BINOP, which is defined here:https://github.com/python/cpython/blob/037245c5ac46c3436f617a1f5d965929754be239/Objects/abstract.c#L759
this calls into PyNumberMethods, found here: https://github.com/python/cpython/blob/98c4433a81a4cd88c7438adbee1f2aa486188ca3/Include/cpython/object.h#L148
Which are a tightly laid out optimized set of number methods available on a particular type
so, if you're looking for a specific definition, you'd probably want the one belonging to, say, int
Well, bool is easier
The "number methods" for bool are here:
and bool_and is defined here: https://github.com/python/cpython/blob/fa7ce080175f65d678a7d5756c94f82887fc9803/Objects/boolobject.c#L84
Integer is a false road, because python ints are uncapped and come from longobject.c
The methods are assigned here: https://github.com/python/cpython/blob/fa1d83db62a545580d9a1a585b2c1fb55961a5c3/Objects/longobject.c#L5592
and defined here: https://github.com/python/cpython/blob/fa1d83db62a545580d9a1a585b2c1fb55961a5c3/Objects/longobject.c#L4673
@true hollow hopefully that answers the question :P
Well, they reference long_bitwise, but that's where it ends: https://github.com/python/cpython/blob/fa1d83db62a545580d9a1a585b2c1fb55961a5c3/Objects/longobject.c#L4552
oh my God thank you so much 😄 😄
damn why did they make a thousand of references and definitions
Mostly because it goes through the standard type resolution code just like everything else
And then when you know precisely what you're looking for there's that additional layer (int -> long) that stifles things
Which calls NB_BINOP, which is defined here:https://github.com/python/cpython/blob/037245c5ac46c3436f617a1f5d965929754be239/Objects/abstract.c#L759
@torpid bridge can you please fix this link so I can click it later :p
works-for-me?
I can't click it :/
It works
I'm on mobile
No, I understand that. The pointers
well, so...
get the sloth item from nb_methods, cast it to a char reference, and then cast it to ???
big confusion time
well
why bother
Mostly because otherwise itd be copied like 20 times
and some code like that in 20 places is not fun to work with
If I'm reading it right
it's just lots of casting
convert nb_methods into a char*, then get the slot, then cast it to a binaryfunc
biggest code golf ever
nb_method is casted to char ptr, and you take the address of the pointer, then cast it to ternaryfunc ptr, then get the result which is some container and get the slot-th result from it
If I’m right
Oh wait
binaryfunc is defined with
typedef PyObject * (*binaryfunc)(PyObject *, PyObject *);
Bruh, didn’t see parentheses there
If you do, basically just copy the definitions and adjust as needed I'd bet
By the way how long does it take to you to compile cpython? For me it takes 5 minutes
Uh
around 5-10 for my laptop, probably much less for my desktop but never noticed having to
It's mostly slow in the parser, ast, interpreter and objects
The unicodeobject takes years
Yeah, you should see rusts syn crate ._.
The automatic code generation is genius imo
I like how a python script helps me code and compile python
What if some day we run out of python interpreters but we only have the cpython source code 
wed have to write a bootstrapper
I don’t like how python tree_macro!: ... looks like
I don't think we need macros in Python at all
#bot-commands
macros scare me
same
Am I doing something wrong? https://github.com/AtieP/cpython-playground-atie/commit/e13dafe559f13f45f636c2be844da457cee019fd
I am basically trying to implement a new operator (!&) which returns the negative and, and when I use it on code, it gives me SyntaxError invalid syntax
Why not just do ~(a & b)?
cpython-playground-atie
Fair point
Hey @true hollow
heya isidentical
I didn't check out the rest of the code, but the problem appears to be that
you created the bitwise_nand rule but didn't referenced it anywhere
what I mean by that is, consider the following grammar;
start: expr
expr: addition | subtraction
addition: INT "+" INT
subtraction: INT "-" INT
multiplication: INT "*" INT
yeah?
In that example, 1 * 2 would simply faily since the rule doesn't actually included in any parent rule definition
so, when you defined a bitwise operator that has a precedence even greater than bitwise_or, then you have to go up and search all occurrences to it
and replace them with your own rule bitwise_nand rule
so my example grammar would have to be refactored like this
+ expr: addition | subtraction | multiplication
- expr: addition | subtraction
in order to have the * operation to be successfully parsed
fair
what you could potentially do, for the sake of simplication is that, make the precedence of NAND between XOR and OR
so that you don't have to replace all occurrences
hm okay
because it would be a lot of work (I presume?) bitwise_or is fairly used in other rules
Also, I don't know how useful it would be for you, but feel free to try python on debug mode to see how actually parser operates
./python -d
well, okay
so
is this okay? ```
bitwise_or[expr_ty]:
| a=bitwise_or '|' b=bitwise_nand { _Py_BinOp(a, BitOr, b, EXTRA) }
| bitwise_nand
bitwise_nand[expr_ty]:
| a=bitwise_nand '!&' b=bitwise_xor { _Py_BinOp(a, BitNand, b, EXTRA) }
| bitwise_xor
bitwise_xor[expr_ty]:
| a=bitwise_xor '^' b=bitwise_and { _Py_BinOp(a, BitXor, b, EXTRA) }
| bitwise_and
by the way, what's the name of this language?
by the way, what's the name of this language?
@true hollow well, this is a custom DSL for ourpegen(Python's parser generator)
Normally, it is a PEG generator but it is like a different flavor to other PEG grammars (they have different notations)
that explains why the plugin i installed for this file extension made the whole file be green
lol
are the any docs, or something (for this language)?
yup
yay
is this okay? ```
bitwise_or[expr_ty]:
| a=bitwise_or '|' b=bitwise_nand { _Py_BinOp(a, BitOr, b, EXTRA) }
| bitwise_nand
bitwise_nand[expr_ty]:
| a=bitwise_nand '!&' b=bitwise_xor { _Py_BinOp(a, BitNand, b, EXTRA) }
| bitwise_xor
bitwise_xor[expr_ty]:
| a=bitwise_xor '^' b=bitwise_and { _Py_BinOp(a, BitXor, b, EXTRA) }
| bitwise_and
@true hollow It looks like it is
nope, doesn't work
nope, doesn't work
@true hollow interesting
let me check it out from my local computer
sure
why this is advanced?
@blissful hornet you're asking why this channel is called this?
yp
A lot of the conversations in this server are geared towards teaching the language so this channel is to carve out space for talking about the language itself.
does anyone make much use of the more-itertools module?
what about even-more-itertools
a lot of the methods there seem like something one would just write something custom for
oh what ha
seems dead
rip
i mean things like this: https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.lstrip
that's something that I'd just write as i went i think, wouldn't think to look up a method for that... so was curious if others used it
itertools++
@true ridge I always run make clean and then make when editing files related to grammar
@true ridge I always run make clean and then make when editing files related to grammar
@true hollow you don't actually have to runmake clean. Justmake regen-pegen && make -j8would be enough
thread count
honestly, I prefer to just make a separate function when doing more complex logic
for compiling on multiple threads
@flat gazelle are you referring to the use of more itertools
yeah
@flat gazelle right, that has been my thought whilst looking through the docs for most of what's here, with the exception of collapse , that's pretty handy it seems
I'll try to fix this
yay finally works
@true hollow congratz
😄
does anyone make much use of the more-itertools module?
@magic python I like the chunking functionality
@boreal umbra yeah - i looked at that and tried to see if i could get that algo from the other day with it but seemed not
so i lost interest 😛
one thing i do think whilst looking through this is perhaps i don't with with iterables enough -- i always just cast to lists as they fit in memory
I have recently come to prefer just for loops rather than comps/itertools for anything more complex than a simple map filter. with yield you can get pretty clean code.
i've been leaning that way, having had to actually read my code more recently
often when writing there's a aim towards making it short / using functions / having a neat comprehension but it kinda becomes pointless i guess when it's harder to debug and read later
for me at least, and some that i work with
unlike haskell, composition of recursion schemes in python just ends up in a mess
i couldn't think of an example for that
probably help if i knew what a recursion scheme was i guess
just think of various smaller functions you compose to get the logic you want.
recursion isn't recursion in the sense of base case and all that jazz then?
you mean having nested list comps or what not
thanks @torpid bridge @true ridge! it finally works 😄
a lot of the more-itertools seems less useful if one is working with pandas as well, series objects can do a lot of this
sorry, bringing that up just made things confusing. Yeah, instead of using things like nested comps, a sizeable portion of itertools and such, you can often get a <5LOC long function that is much more readable
yeah - so hear you'd prioritise that over reinventing the wheel?
in that - you'd rather a clear small function within your code than calling a more obscure part of itertools, even though the functionality is similar
yeah
do you guys think the ++ operator can come to python some day?
i really miss it for increasing lambdas or comprehensions
probably not
i know itertools.count is a thing, but anyways, i like the ++ syntax :P
++ is pretty useless if you have += 1
or even simple range iterator
or count, in the end
!zen special
Special cases aren't special enough to break the rules.
There are very few cases when you really need ++, yeah
+= 1 and -= 1 are mostly suitable
if you are not using ++ for its special and not really readable behavior, I don't see a point
AFAIK C++ also overrides ++ so that it acts as next for iterators
@unkempt rock how would you use ++ in a comprehension?
well, thinking a bit about it, 95% can be done with ranges, so, that's true, the language shouldn't change because maybe 5%
i remember when someone first said to me, "python needs ++ less than other languages." It seemed absurd at first: how can a language need incrementing less than other languages?
But the for-loop constructs are different, and explain it
also using ++ in comprehensions implies assignment in comprehensions
which implies either it won't work or you'll return to the codebase in a few months and have no clue what's going on
Besides, even if it wants in line callers and setters, python's new := could be thought to grow I'd say
This channel is meant for discussing Python itself, not for general help @blissful hornet
what do u mean python itself
Discussion on the use cases, implementation
and future of the Python programming language
including PEPs, advanced language concepts,
new releases, the standard library, and the
overall design of the language.
Your question would be more fit to be asked in a help channel see #❓|how-to-get-help
ok
If you have a passthrough function which utilises **kwargs what would be the way to go about annotating that, is it covered in a PEP?
!pep 612
Hmm
Type annotations always seem so promising but the effort involved to use them properly makes it so hard to want to use them
@safe hedge why does it need to be annotated? By definition it's a dict
Right. But I wondered if there was some way to say - these are the params for this other function
I supposed it's used as a way to not write all the parameters out
def foo(x, **kwargs):
print(x)
bar(**kwargs)
def bar(**kwargs):
baz(**kwargs)
baz(**kwargs)
...
def spam(*, fizz=1, buzz=2, ham=None):
...
And only half-annotating things seems worse than not annotating them at all imo
If it's something widely used, you could make a special Options object (a NamedTuple, for example)
I don't really want to do that becausem, for example wrapping a function from another library, that would mean you have to ensure you keep that options class up to date rather than just defaulting to passing any arguments through
well, yes
hey yall
I want some people I know who dont understand OOP to be able to just override a function by passing it into a method call.
class someThing:
def __init__(self):
self.arbitraryString = 'thing'
def dynamicAddMethod(self, **kwargs):
for key, value in kwargs.items():
getattr(self, key) = types.MethodType(value, self)
this gives me back a "cant assign to a function call". I take it that function calls are immutable?
you want setattr(self, key, ...)
omfg. Thank you. Lol.
but wouldn't it be easier to teach them how to subclass than how to use your unusual thing?
So I do a computed attribute that checks for issubclass & the type(self).__name for that.
We got a mixed bag of staff. Some net engr & some long time programmers. Trying to teach them all this is sometimes like herding cats.
Horse to water, can't make the horse drink, if you catch my drift.
Trying to check what function parameters are legal in Python from the docs itself https://docs.python.org/3.8/reference/compound_stmts.html#function-definitions --- but stumped that a function definition like def func(a,b,*,c,d) doesn't seem to be covered in the regex patterns found in the docs?
@mossy heron which regex pattern?
I'm wanting to check in particular if I can use something like func(a,b,*,c,d) along with *args and **kwargs but couldn't find the ,*, part in the docs.
@spark magnet Maybe regex pattern is not the right term.
I'm referring to the box immediately found after the first sentence in this section https://docs.python.org/3.8/reference/compound_stmts.html#function-definitions
Looking at this in particular
parameter_list ::= defparameter ("," defparameter)* "," "/" ["," [parameter_list_no_posonly]]
| parameter_list_no_posonly
parameter_list_no_posonly ::= defparameter ("," defparameter)* ["," [parameter_list_starargs]]
| parameter_list_starargs
parameter_list_starargs ::= "*" [parameter] ("," defparameter)* ["," ["**" parameter [","]]]
| "**" parameter [","]
parameter ::= identifier [":" expression]
defparameter ::= parameter ["=" expression]
I believe that its the order in which you define them.
The first two arguments are args and key word args., the Middle (*) designates args, and then finally all the way to the right the ** specifies kwargs. Once you put * or ** in the params I do not believe you can put arbitrary args like "c" and "d" after it. Its the order in which you are specifying the parameters.
Someone else may understand the question better, but the answer on this S.O. lays it out nicely.
https://stackoverflow.com/questions/36901/what-does-double-star-asterisk-and-star-asterisk-do-for-parameters
It may help.
@mossy heron i see what you mean: the , * , doesn't seem to be accounted for in the grammar.
i thought the docs were @mossy heron oh, it's: "*" [parameter] ("," defparameter)*
the parameter is optional
Ahhh!! That's it. Thank you!
And thanks as well @cunning oxide I'll read that as well.
@mossy heron in the context of a single * (with no variable to catch all other args), the * means that all parameters that follow must be passed by keyword, so supose we have the function py def foo(a, b, *, c=None, d=None): print(a, b, c, d)then foo(1, 2) and foo(1, 2, d=4) would be legal function calls but foo(1, 2, 3) would raise an error as it recieved too many positional arguments
I have a question about subclass inheritance, which of these ways of making a subclass is better? Do they both accomplish the same thing?
light mode theme is better 🙂
init in the subclass or just putting it in the parentheses of the subclass
The second one isn't a subclass. I would not do that.
To my eye, it looks like a mistake. someone who didn't know how subclassing works.
also I think it will have a NameError for "filepath"
And in case of inheritance, use super everywhere. (this would not even work in your example 2, I know)
great the second one is from the python course im taking haha
I would only overwrite methods in the child class that are different from that of the parent, if in that bottom example Checking is supposed to have the same __init__ as the parent I don't see a reason to create an __init__ which just initialises the parent as the inherited __init__ method should do that anyway
@crisp fulcrum what course is that?
it's been pretty good so far
yikes, that's disappointing
Is it really written class Checking then in Checking.__init__, Account.__init__(self, filepath) ? 👀
to be fair i just got to where he got an error and updated the code to fix it
but still the second init was what i was confused about
@mossy heron in the context of a single
*(with no variable to catch all other args), the*means that all parameters that follow must be passed by keyword, so supose we have the functionpy def foo(a, b, *, c=None, d=None): print(a, b, c, d)thenfoo(1, 2)andfoo(1, 2, d=4)would be legal function calls butfoo(1, 2, 3)would raise an error as it recieved too many positional arguments
@modern night Thank you! As mentioned earlier, I wanted to check if I can use something likefunc(a,b,*,c,d)along with*argsand**kwargs. (Looking at the grammar, no, I cannot. I can't have both,*,and*args. For fuller context, I was trying to help this person https://topanswers.xyz/python?q=1403 and I'm settling with the answer that I cannot pass positional arguments as keywords arguments if there are a dynamic number of arguments.
Is that a course on basic things for 200 dollars?
i think all udemy courses are way overpriced so they can sell you on 90% off sales... i got it for i think $12
@crisp fulcrum How does an Udemy course differ from free Youtube videos?
@crisp fulcrum I do recommend this one: https://dabeaz-course.github.io/practical-python/
@mossy heron You can use / if you want to make arguments positional only
but still the second
__init__was what i was confused about
If you understand what ifself, then you understood the whole thing. It literally calls theAccount's__init__method, giving it as aselfargument the new instance ofChecking, meaning that theAccountinitializer will initialise the instance ofChecking.
@mossy heron You can use
/if you want to make arguments positional only
@grave jolt Interesting!! I was wondering what that meant in the grammar. I've never seen anyone use it before.
and this one also by Peter Norvig: https://www.udacity.com/course/design-of-computer-programs--cs212
ok
@mossy heron
def f(a, b, /, c): ...
f(1, 2, 3) # ok
f(1, 2, c=3) # ok
f(a=1, b=2) # error
this also allows using any names for kwargs:
def f(a, **kwargs): ...
f(1, a=5) # error: multiple values for `a`
def f(a, /, **kwargs): ...
f(1, a=5) # ok
Super cool! Thanks for sharing that!
@grand crag wouldn't you be doing that everytime you make an instance of the Checking class?
Each time a Checking instance is created, the Account's "constructor" is called with the newly created Checking instance as a self parameter.
hi guys, wondering what an @lru_cache(none) decorator does on a function
i know what lru stands for but not really familiar with it totally
that is, functools.lru_cache
it memoizes the function
it saves the result of the function call into a cache so next time you call the function with the same arguments it just looks up the cache
In [2]: @lru_cache
...: def test(n):
...: print(n)
...: return n
...:
In [3]: test(5)
5
Out[3]: 5
In [4]: test(5)
Out[4]: 5
Hi, why cant I import cache from functools? https://docs.python.org/3/library/functools.html#functools.cache ```
from functools import cache
ImportError: cannot import name 'cache' from 'functools' (/usr/lib/python3.8/functools.py)```
oh wait, that's only in 3.9 😦
what you guys think about functools.singledispatch?
I've never needed it but have no strong feelings about its existence.
It has always seemed sort of odd to me, but I suppose there's probably some niche where it's useful.
I don't understand why they went out of their way to implement singledispatch but not a multipledispatch version
it's so inconsistent
I've never seen singledispatch before, but as far as I can tell it is similar to the way R defines functions for different datatypes which are called depending on what you pass it.
It's a way to basically add a method to all classes without modifying the classes?
What would multipledispatch look like?
something like this: https://github.com/salt-die/Snippets/blob/master/overload.py
So just adding more arguments to dispatch on basically
yep
@deft pagoda thanks but i dont fully understand. is it more just for speed purposes? so u dont have to run the function again if it has the same arguments?
i appreciate the help, but from the example it just wasnt that clear
so u dont have to run the function again if it has the same arguments ?
yes
if the function is expensive, it can speed up your program by a whole lot
thanks guys. i guess its a decorator that i should use more often!
it's not a guaranteed speedup, it's only useful in certain cases
hey pythonistas, need some sugggestion if you know any tool/library to cross compile binaries of CLIs built in python?
I've used pyinstaller, but it have limitation that it doesn't cross compile for all platforms
@zenith frigate this is a discussion channel so I'd open a help session (see #❓|how-to-get-help). Unfortunately I don't know the answer off the top of my head.
pyoxidizer?
okay @boreal umbra, thanks for opening help seeiosn 🙂
thanks @rapid yew , will check this one
I've complained before that the servers at my uni only run 3.6. There's one that has 3.7 and I have no idea how much fighting was required to make that happen. The updates to typing in 3.9 are making the slowness to adopt all the more frustrating.
expecting a big changelogs of fixes in upcoming release of 3.9
as it happened earlier with 3.8
@zenith frigate 3.9 was released the other week already
This was a reference to 3.9.1 I believe.
ahh okay, that makes more sense
is python 3.9 backward compatible with 3.8? will it break 3.8 code after upgrade to 3.9?
no for the second question
I mean I don't think that's entirely true...
Stuff has been removed in 3.9
If you used anything in this section your code will break:
https://docs.python.org/3.9/whatsnew/3.9.html#removed
oh
Of course all that stuff has been deprecated for at least 1 version
So you should have seen it coming
But there is the possibility that code which ran in 3.8 will error in 3.9
@forest flicker the idea of x.y.z versioning is that any time you increase the y number, you're just adding things. new y versions shouldn't break code from earlier x versions. x versions aren't required to be backwards compatible. z is just for fixes that don't change what any code is meant to do.
Though it may be that you already know that and you're thinking of the few instances where a y version of python3 broke earlier code.
@boreal umbra that's semver that you're describing - semantic versioning. Python does not use semantic versioning.
@raven ridge doesn't it use it... mostly?
"mostly" using it leaves you in exactly the same situation as you're in if it isn't used at all. You do not know whether a minor version introduced backwards incompatible changes.
fair enough
unless there's some other system I'm not aware of, Python's version numbers are clearly inspired by semver
what would you call that?
doesn't semver only introduce breaking changes on major versions?
python does them in minors
@boreal umbra
@sacred yew I thought breaking changes in Python were few and far between, but maybe I'm wrong
Yeah @boreal umbra https://docs.python.org/3.9/whatsnew/3.9.html#removed
They remove stuff in "minor" versions. Albeit mostly stuff which has been deprecated for a long while
I realize it's not applying semver in the true sense but as far as I can tell the versioning is semver inspired
I wonder if there would be more major releases if a transition to 4 wouldn't carry the baggage that 2->3 had
I mean there's no guarantee it would though right?
Since there are breaking changes between 3.7->3.8->3.9 etc what would a move to 4.0 even look like
I guess it would give them a clean slate as far as backwards compatibility goes
@dense mauve that doesn't look like a complete question but take a look at the instructions on #❓|how-to-get-help
I realize it's not applying semver in the true sense but as far as I can tell the versioning is semver inspired
@boreal umbra no. Python's versioning strategy predates semver. Major versions break a lot, minor versions hopefully don't break much, patch versions usually don't break anything.
The relationship is the other way around: semver is an attempt to codify rules around version numbers, which have historically used x.y.z to roughly indicate the amount of changes in the release (bumping x means there's more changes than if only y was bumped, etc), into something useful and semantically meaningful, rather than just an approximation or a hand waving.
semver's big idea is that instead of x just meaning more changes than y or z, it should mean a different type of changes.
To put it more pithily: versioning strategies like Python's are the problem that semver set out to fix.
for the most part yeah, but it depends
if you are complete beginner in programming than start with computer science first
ie learning what are arrays variables, string, integers
i suggest you do harvards free cs course cs50
Introduction to the intellectual enterprises of computer science and the art of programming. This course teaches students how to think algorithmically and solve problems efficiently. Topics include abstraction, algorithms, data structures, encapsulation, resource management, s...
ok
Thanks I already know java upto opp.
this is a really good resource to get you started
Helsingin yliopiston kaikille avoin ja ilmainen ohjelmoinnin perusteet opettava verkkokurssi. Kurssilla perehdytään nykyaikaisen ohjelmoinnin perusideoihin sekä ohjelmoinnissa käytettävien työvälineiden lisäksi algoritmien laatimiseen. Kurssille osallistuminen ei vaadi ennakko...
ok
Thanks I already know java upto opp.
@shell needle hey then you will have no trouble with python
for this course I am learning python.
But I never done network and database with java.
so should I follow that roadmap?
But I never done network and database with java.
so do you want to get into cybersecurity and networking with python?
https://cybersecuritybase.mooc.fi/
@shell needle yeah this is pretty good if you wanna get into networking
Helsingin yliopiston kaikille avoin ja ilmainen ohjelmoinnin perusteet opettava verkkokurssi. Kurssilla perehdytään nykyaikaisen ohjelmoinnin perusideoihin sekä ohjelmoinnissa käytettävien työvälineiden lisäksi algoritmien laatimiseen. Kurssille osallistuminen ei vaadi ennakko...
although refer to python docs before doing this cource
https://docs.python.org/3/tutorial/index.html
this should do you well
this will get you familiar with python syntax and all after which you can move on to whatever you want to do
Thanks for your reply <3
I have already learn upto opp in python.
thats cool
shouild i learn networking with python next?
dm me, mods here are strict
@unkempt rock I am not a native english guy.
can u explain your last messege plzz
wait i will message you personally. this group is is not for casual talk
so why pip is not adding the installed moduels to PATH on linux
@blissful hornet you need to add the installation folder to PATH yourself
im guessing its ~/.local/bin?
also wrong channel
this is not a help channel
@livid mason @blissful hornet
Why does str.join require the iterable to only have strings instead of calling str on each item?
it would probably be somewhat error prone
huh?
Python generally tries not to convert types for you
Other than floats and integers
It's a fairly consistent design philosophy across the language
Although I will say, I don't see too many downsides to coercion in this case
with + it could get very messy and I am grateful that Python does not convert to string in that case
glares at php
I guess honestly, because python doesn't implicitly convert types for you, having str.join would be a special case that breaks the expectation and consistency set by the language
So, while there have been moments where I've just been like "gah you know i meant to use strings for a join" i am fine with the decision made here.
Also it brings some kind of safety to the language, if you accidentally pass something else than a string to str.join, it will error out
want to join strings? pass strings 🙃
Hmm you guys wanna do a quick help here?
@pliant flame this is strictly a discussion channel; take a look at #❓|how-to-get-help
Python generally tries not to convert types for you
@paper echo imagine having an iterable of DataFrames and trying to usestr.joinwhere it would first dostr()on each dataframe, that would be terrible
Honestly I think it's strictly bc of __str__ that they don't coerce things
It's different when you're doing print bc it's obvious what you're doing
But not so much with str.join
I mean, there isn't much ambiguity with str.join either, you're trying to get a string consisting of items from iterable joined with the specified separator
The problem I'd have with that is that sometimes you don't just want str or passing in the wrong thing would cause confusion with the implicit conversions. implicit repr would be clearer but doesn't make much sense either
imagine having an iterable of DataFrames and trying to use
str.joinwhere it would first dostr()on each dataframe, that would be terrible
@swift imp doingstr(d) for d in iterableinstead ofiterableis honestly not that bad
or map(str, iterable)
This seems quite off-topic, this channel is for discussing the language itself
Hey, I'm trying to compile python with emscripten for a target wasm32-wasi build, but for some weird reason, it wont produce wasm32 code, even though it successfully compiles, I'm using a modified https://github.com/e0gs/cpython-emscripten with added wasm32-wasi support which configures python with https://github.com/e0gs/cpython-emscripten/blob/master/3.5.2/Makefile
CFLAGS=-m32 LDFLAGS=-m32 CONFIG_SITE=./config.site READELF=true emconfigure ./configure --without-threads --without-pymalloc --disable-shared --disable-ipv6 --without-gcc --host=wasm32-wasi --build=$(shell $(BUILD)/config.guess) --prefix=$(INSTALL);
...
CFLAGS=-Wno-implicit-function-declaration emmake make HOSTPYTHON=$(HOSTPYTHON) HOSTPGEN=$(HOSTPGEN) CROSS_COMPILE=yes $(LIB)
Yet it wont produce a wasm32 python library, anyone might know what I might have missed?
Hello. Good Afternoon.
someone has performance issue with matplotlib gui on windows 10?
Hey @unkempt rock, this isn't an help channel, see #❓|how-to-get-help
@unkempt rock If you want to get help with a specific question, see #❓|how-to-get-help and claim a help channel. This channel is for meta discussions about the Python language.
Hello everyone, I'm looking for the implementation that occur when I'm taking an object and parsing it to a new one
When I call a function, the __call__ method is used
When I print a variable, the __str__ is used (or the __repr__)
Which dunder is used on the var2 when I do
var1 = var2
Can I .copy() implicitly then ?
no
Isn't there a way to do it if var2 is a class or something else ?
no, pure assignment does not call any methods you can access from python (unless you override __builtins__ or redirect the globals() pointer, but neither of those would make it viable to make it work AFAIK.)
Could you please explain how I can override __builtins__ or redirect globals() ?
again, neither of those would actually help.
if i create a temp table like CREATE TEMPORARY TABLE x (LIKE y) is there a way to make sqlalchemy generate a Table object based off the new temp table x ?
@elder lodge someone in #databases might be able to help you with that
Does anyone else feel like slice assignment with lists is really hacky?
At least when you're trying to set it to a single value
Here's an example of what I'm talking about
a = [0,1,2,3,4,5]
a[3:] = 3 #this causes an error
a[3:] = [3] * 3 #this doesn't
a[3:] = [3 for _ in a[3:]] #this... works?
Compare that to numpy
a[3:] = 3 # works JUST FINE
you can do a[3:] = [3] (though that doesn't work for slices with a step). Numpy arrays contain exclusively scalars, but in python there would be the issue of
l = [()] * 10
l[3:] = (3,)
``` what should this do
Hmm, I didn't try a[3:] = [3]
I've just been doing uh....
a[3:] = repeat(3,len(a[3:]))
Yeah 😦
Just another reason to like numpy and itertools
Since I think repeat works for any object
Does anyone else feel like slice assignment with lists is really hacky?
@pseudo cradle it is IMO
I played with it before when implementing a sliceable list
like one where slices are views of the original
assignment with extended slices is just super weird.
@pseudo cradle i disgree, numpy broadcasting is implicit and potentially unexpected/undesired
it's python being strict, like in the str.join case we discussed earlier
and i think overall it's a good feature of the language
Yeah I don't really agree that this part specifically is hacky
We can reassign sub sections of lists using iterables, makes sense to me tbh
In fact, I'd think it would be weird to have broadcast rules for assigning subsets of lists, but not for other operations
I feel like neither of these should work:
>>> l = [1, 2, 3, 4, 5]
>>> l[1:4] = ['a']
>>> l
[1, 'a', 5]
>>> l[1:2] = ['a', 'b', 'c', 'd', 'e']
>>> l
[1, 'a', 'b', 'c', 'd', 'e', 5]
That's neat.
I think it's demonic
then again there's no other way to insert stuff so
I guess this is it but well 🤷♂️
insert more than 1 element
Syntax is hard to grok at first.
okay like conceptually
I would think that the first case is weird because you're replacing a subsequence with another of different length
that is super weird looking
Replacing the range specified by the slice with the contents of another list.
but it's still understandable in some esoteric way
the second, though, is just wrong IMO
like imagine if that was reading
"get the 1st element, inclusive, to the 2nd element, exclusive"
It's [start:stop-1]
now that we're writing
"get the 1st element, inclusive, to the 2nd element, exclusive", and replace that with this iterable that is not the same size
there should be a separate API for that
I will say, though, that I have never had a need for any of this
In [4]: l = [1,2,3,4,5]
In [5]: l[1] = "a", "b", "c"
In [6]: l
Out[6]: [1, ('a', 'b', 'c'), 3, 4, 5]
In [7]: l = [1,2,3,4,5]
In [8]: l[1:2] = "a", "b", "c"
In [9]: l
Out[9]: [1, 'a', 'b', 'c', 3, 4, 5]
why does this work this way
slice assignment is a special list feature
I guess it can take a tuple as well
It'll use the contents of whatever you're assigning instead of using it directly
it does
so l[1:0] returns an empty list but assigning to it like l[1:0] = x, y, z puts x,y,z in the list extending it
it can take any iterable
@pseudo cradle i disgree, numpy broadcasting is implicit and potentially unexpected/undesired
@paper echo
Hard disagree here. Broad casting is derived from outer products of vectors and makes perfect sense
yeah but lists are not meant to represent vectors
^
They're talking about numpy...
They're talking about numpy...
@swift imp yes, but in the context of howlistslice assignment should work
Hello, someone knows JavaScript?
Hello, someone knows JavaScript?
@lucid mason this is a Python server, and this is a channel for language discussion. if your question is tangentially related to web development in Python, you can try #web-development.
@gleaming rover many tnx, i didn't see this channel
Why does unary + exist in Python?
Seems pretty useless.
!tempmute @unkempt rock 1d Breaking most of our rules in a single message is not a good start
:incoming_envelope: :ok_hand: applied mute to @unkempt rock until 2020-10-15 23:58 (23 hours and 59 minutes).
I'd guess it's mostly there because - is a thing
@grave jolt i think it's one of those things that is for numpy's use (and other things like it)
Been there since python 1 as far as I can see. unary neg is technically one of the most commonly used things, so why not also do +
could be
just use abs
Could just be that it's a useful thing to have when using the language as a calculator
Or accounting style tabulation.
There's really no downsides to having it around, even if it only has a few uses
I think that's a bit different with the + having the real world use and other unary operations that have to be in the language, and @ being nice but not really necessary with no actual use in cpython itself beyond a free operator
Out of curiosity, I ran egrep "__pos__" -r . | wc -l over the 3.8 standard library - there's 88 mentions.
__matmul__ has slightly fewer, with 56.
It's roughly expected, considering __neg__ is mentioned 135 times
