#internals-and-peps

1 messages · Page 77 of 1

safe hedge
#

That seems like a front-end problem which you wouldn't typically solve in Python anyway

raven ridge
#

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.

slow wadi
#

no timezone works when it works... until it doesn't and you hate life for a weekend

safe hedge
#

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?

slow wadi
#

or scheduling a meeting with folks in another timezone

#

Python is everywhere, doing everything

raven ridge
#

Sure, absolutely.

safe hedge
#

Only time I've worked with input dates like that they came from the web and I let JS do the conversion

raven ridge
#

what did you let it convert to?

safe hedge
#

UTC

raven ridge
#

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.

safe hedge
#

The UTC time doesn't change...

#

That's still a frontend problem...

raven ridge
#

no - that's why using it is wrong.

safe hedge
#

If I send out a message at X UTC time that will be the correct time whatever the users timezone.

raven ridge
#

Right. But the user's meeting isn't scheduled in UTC. It's scheduled in an actual timezone.

safe hedge
#

You convert the user selected datetime to the UTC time. Do everything in UTC after that

raven ridge
#

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.

safe hedge
#

But then you converted the datetime wrong in the first place...

gleaming rover
#

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

raven ridge
#

not if you don't store a timezone identifier, you can't.

gleaming rover
#

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?

safe hedge
#

If they say - I want a meeting on X date at Y time in Z tz and you convert that to the UTC time

raven ridge
#

there's no way to get from a UTC time back to the time the user originally entered.

safe hedge
#

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

gleaming rover
#

like the point is that you are storing timezone-aware datetime objects (or the equivalent), right

raven ridge
#

not if their offset rules change in between when the scheduling happened and when the meeting happens.

safe hedge
#

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

raven ridge
#

Yep, bingo.

#

that's exactly the case where what you're proposing doesn't work.

safe hedge
#

In that case though you're going to break unless your timezone info has been updated anyway...

raven ridge
#

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.

amber nexus
#

Theres a nice video from computerphile about the nightmare of dealing with timezones

slow wadi
amber nexus
#

Thats the one

slow wadi
#

was just about to paste

#

i watched this video, and immediately forgot everything and vowed to never try to understand all this time crap

raven ridge
#

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.

slow wadi
#

and then there's leap seconds!

safe hedge
#

Just move to UTC

#

Save us all from this stress

slow wadi
#

that's actually a proposed solution

#

just don't give a crap if the sun is directly overhead at 1200

safe hedge
#

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

raven ridge
#

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.

safe hedge
#

That seems worse than removing timezones

gleaming rover
#

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

safe hedge
#

Under that system you would end up with countries having weird timezone enclaves/exclabes

gleaming rover
#

^

#

what I was about to say

raven ridge
#

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.

#

🙂

gleaming rover
#

indeed it is not

safe hedge
#

How is that more practical though?

slow wadi
#

after the AI wars we won't be able to see the sun anyway

safe hedge
#

I'm still not sure I see any particular issue with removing timezones

slow wadi
#

might as well all use UTC

raven ridge
gleaming rover
#

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

safe hedge
#

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

raven ridge
#

read the whole essay. It's really good, and will give you a much more nuanced view of the topic.

safe hedge
#

The solar day issue is definitely more of a problem

unkempt rock
#

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

amber nexus
#

Not the right channel for that question

unkempt rock
#

oh sorry

heady siren
#

Anyone use Cython?

#

Is it better that pypy

teal yacht
#

it's solving different problems

safe hedge
#

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

cloud crypt
#

Cython can be faster than pypy if you use enough C things there

flat gazelle
#

it can also be slower since there is some cost of running converting to C

teal yacht
#

pyx files are compiled during the project build

flat gazelle
#

I meant converting the runtime representations of python objects to things C can operate on.

teal yacht
#

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

flat gazelle
#

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
true hollow
#

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?

teal yacht
#

you can't

true hollow
#

damn

teal yacht
#

best case scenario is the file in question is part of a dynamic lib and you only have to build the library

true hollow
#

i am modifying the builtins c file for fun

undone hare
#

You can build it again and put it early in the python path, and the library should import it

storm portal
#

has anyone here developed any desktop apps using python?

true hollow
#

btw

#

what's all the clinic stuff?

gleaming rover
true hollow
#

yeah that

#

thanks

true hollow
#

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

ivory cosmos
#

who will tell me to get binary data of any type of file in python or somewhere else

warped hamlet
#

@safe oracle can you help me with this python problem

sacred yew
warped hamlet
#

@sacred yew sorry

manic hatch
#

Hello

boreal umbra
#

@manic hatch Hi, what's your favorite PEP?

manic hatch
#

Pep 8

#

Thats latest

boreal umbra
#

but pep 8 didn't introduce a new feature

manic hatch
#

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

boreal umbra
#

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.

manic hatch
cloud crypt
#

My favorite not-yet-implemented PEP is perhaps 505

boreal umbra
#

I know a lot of people want that but I'm not sure if I'd use it.

violet jetty
#

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.

uncut sage
#

@violet jetty wow, that's a really advanced and IMO worthwhile exercise.

#

Speech to text for mathematical formulas is an amazing project

violet jetty
#

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.

grave jolt
#

@unkempt rock Don't bump your help channel in other channels. The topic of this channel is stated in its description.

unkempt rock
#

oh sry i ll delete the mess

unkempt rock
#

only dict keys must be hashable, am i right?

undone hare
#

Not only, but yes, they have to be hashable

unkempt rock
#

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

sacred tinsel
#

yes, correct

#

values do not need to be hashable

unkempt rock
#

okay, thanks :D

sacred tinsel
#

I'm fairly confident in saying that any object in Python can be a value in a dictionary

distant quartz
#

does anyone know of a library/package to validate emails and their MX? every package seems to fail miserably at it

fallen slateBOT
#

: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).

spark parcel
#

<@&267629731250176001> they spread to other channels

north root
#

yes

brave storm
#

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

pliant tusk
#

@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

distant quartz
#

this is so sad I guess im going to have to pay to validate email addresses

radiant fulcrum
#

🤔

teal yacht
#

@pliant tusk that's just overloading str isn't it

distant quartz
#

for pretty much every single python library, you can type in anything@anything.com, ask to check MX, and it won't work

pliant tusk
#

nope @teal yacht

#

uses sys.settrace

teal yacht
#

Oh wait no I can't read

pliant tusk
#

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

pliant tusk
#
>>> x = (NotAValue(),)
>>> print(x)
(<NULL>,)
>>> print(x[0])
[1]    81135 segmentation fault  python3``` now i may have gone a bit overboard
pale sparrow
#

anyone know sentence probabilities here ?

uncut sun
#

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?

lone wagon
hollow crane
#

@violet jetty could replace the symbols with words

true hollow
hollow crane
#

maybe so it's a different color

true hollow
#

That makes no sense lol

hollow crane
#

i don't know as you can probably tell

#

you mean why is the python version etc?

#

didnt look at the link

true hollow
#

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

hollow crane
#

ye

#

but yeah different colour and separation from output would be my guess

#

i don't know though

teal yacht
#

@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

true hollow
#

ahhhhhh okay

#

that makes a lot of sense

#

so only desired input will be greped

teal yacht
#

yes

#

the prompt also is outputed to stderr

raven ridge
#

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.

hollow crane
#

i was thinking that's the point but like

#

why is that useful

#

-c "<code>" wouldn't need it

unkempt rock
#

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))```
grave jolt
sacred yew
low lagoon
#

Please read channel descriptions before posting.

paper merlin
#

guys

#

anone who can make a botnet with python sockets

gleaming rover
#

anone who can make a botnet with python sockets
@paper merlin wrong channel, this is for language discussion. try #❓|how-to-get-help.

paper merlin
#

ok

gleaming rover
feral stone
#

Interesting, interesting.

gleaming rover
#

do you use functional languages?

feral stone
#

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.

gleaming rover
#

F#, Scheme, Clojure?

#

no, functional programming languages

feral stone
#

No to all of those.

gleaming rover
#

are you familiar with the term?

feral stone
#

It's been a while so it's not as familiar to me right now.

gleaming rover
#

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

feral stone
#

That sounds like it could accomplish a similar task.

ivory cosmos
#

hello

feral stone
#

Ideally I would want it to be something official that lightens the need for many nested if statements.

#

For efficiency.

ivory cosmos
#

who is the person who know python well please help I will share screen with him

#

is there anyone

feral stone
#

Or rather, a way to perform the same task, but in a less open and computationally-expensive way.

gleaming rover
#

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)"
     | }
feral stone
#

Sounds good to me.

#

Yeah this would be what I would expect.

ivory cosmos
#

no help does not work

#

no one helps well

gleaming rover
#

no help does not work
@ivory cosmos also, this is not the right channel. this is a channel for language discussion

grave jolt
#

By the way, if class patterns are a thing, would something like this be conceivably possible?

#
Point(x, y) = p
gleaming rover
#

I certainly hope so

#

🥴

raven ridge
#

@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
#

@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.

raven ridge
#

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.

gleaming rover
#

yup, that's a good observation too

undone hare
#

The LL(1) parser is still the default in 3.9

gleaming rover
#

The LL(1) parser is still the default in 3.9
@undone hare huh

#

are you sure?

raven ridge
#

That's not what the release notes say.

gleaming rover
#

^

undone hare
#

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

true hollow
#

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

undone hare
#

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

spark magnet
cloud crypt
#

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

undone hare
#

I don’t think an inline call really matters for CPython

cloud crypt
#

I have written a (de)serialization library for on project and trust me, function calls are expensive

undone hare
#

Is that your 1 million recursion limit project haha

cloud crypt
#

nah

#

haha

#

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

true ridge
cloud crypt
#

yoo isidentical back

#

thanks

raven ridge
#

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.

solemn topaz
#

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

undone hare
solemn topaz
#

i have asked there but havent gotten an answare in 1 hour

#

@undone hare never got help so it closed it self LUL

undone hare
#

Well, this is still not an help channel

modern frigate
#

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.

teal yacht
#

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

peak spoke
#

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

spice pecan
#

It doesn't exactly make the data smaller, it just generates a value such that equal items will have equal hashes

modern frigate
#

SHA, really. (That is all i've worked with)

teal yacht
#

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

undone hare
#

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

true hollow
#

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

wet obsidian
true ridge
#

ceval.c

true hollow
#

thanks

#

now gotta study 5700 lines of code 😄

true ridge
#

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

true hollow
#

ah okay

#

hm, there is an opcode_targets.h file

#

should i do something to it beforehand?

true ridge
#

yeah

#

There are empty fields

#

fill one of them with something like &&TARGET_BINARY_TORANGE

true hollow
#

i remember setting Atie_kind to 26 in some struct in Python-ast.h

true ridge
#

actually, that is an auto-generated file

true hollow
#

ah

true ridge
#

you need to make changes on the Parser/Python.asdl

true hollow
#

i did

#

in the line that was like Break | Pass, i appended | Atie

#

i basically made a pass replica

true ridge
#

in the line that was like Break | Pass, i appended | Atie
@true hollow looks good

true hollow
#

sorry if i sound so noob 😅
i never expected cpython be soo complicated

true ridge
#

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

true hollow
#

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

true ridge
#

yeah, new parser changed alot

true hollow
#

like, imitating pass, using the search function on github, reading a pep that was 339?

true ridge
#

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

true hollow
#

thanks!

cunning hull
#

hi

#

what is the problem here

fading smelt
#

idk

#

Some errors dont have enough info

#

like append

cunning hull
#

the code is correct

#

do you have any idea how to run it

#

???

fading smelt
#

wdym

#

what idle are you using

cunning hull
#

no i mean from cmd

#

im using pycharm

fading smelt
#

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

true hollow
#

tbh I gave up making a new keyword

#

I will try again later when I've studied cpython more deeply

unkempt rock
#

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

teal yacht
#

Are we on LinkedIn now ?

boreal umbra
#

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?

peak spoke
#

I recall it was just a side effect of a better underlying implementation, so there's almost no cost to it

sacred tinsel
#

that doesn't necessarily justify it being in the spec though

boreal umbra
#

my objection is to adding it to the spec

teal yacht
#

adding it to the spec has a cost tho, it means future implementations can't not have that property without being backward incompatible

sacred tinsel
#

@boreal umbra what's your reasoning against?

teal yacht
#

i'm guessing what i just said

boreal umbra
#

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

sacred tinsel
#

I've come across situations where it was convenient, but the lookups could have been done by position instead, that is true

boreal umbra
#

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

sacred tinsel
#

that's basically my usecase, yes oh it's not, I misread

boreal umbra
#

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.

sacred tinsel
#

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

boreal umbra
#

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.

peak spoke
boreal umbra
#

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.

true ridge
#

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'

boreal umbra
#

@true ridge sorry, I don't think I understand what you mean

teal yacht
#

why should we restrict future implementations to preserve order of insertion

true ridge
#

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.

teal yacht
#

it is, if someone wants an order-preserving dict, they can use OrderedDict, they don't need to rely on dict's implementation details

true ridge
#

Depends on the use case, yes

boreal umbra
#

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.

true ridge
#

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.

boreal umbra
#

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

teal yacht
#

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

boreal umbra
#

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.

teal yacht
#

one can always dream :p

boreal umbra
#

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.

paper echo
#

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

boreal umbra
#

yes, you'd basically have to do something like (MyClass.__call__ @ sorted), I think

paper echo
#

OrderedDict.__init__ @ sorted

#

yuck, takes all the elgance out of it

boreal umbra
#

would you also have to do it for init?

paper echo
#

hm.

boreal umbra
#

actually that wouldn't even work

paper echo
#

what if type(OrderedDict) has __matmul__

boreal umbra
#

because if you call init directly then a new object doesn't get made

paper echo
#

ah true it'd be __new__?

boreal umbra
#

not sure if that would call __init__ though

paper echo
#

actually i'm not sure how that works. what's the "functional" version of class instantiation?

boreal umbra
#

I thought that all happened in type.__call__

paper echo
#

probably

boreal umbra
#

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

unkempt rock
#

what does __ do

boreal umbra
#

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

paper echo
#

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__

boreal umbra
#

that would return type, yes?

paper echo
#

in this case yes

#

but it could be any subclass of type

boreal umbra
#

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)

paper echo
#

sure

#

but | is just... "or"

#

@ to mean function composition would be such a leaky abstraction

#

since it's already mis-appropriating the matmul operator

boreal umbra
#

@paper echo in what way is it mis appropriating it?

paper echo
#

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

boreal umbra
#

@ was used for decorators first and that's already a composition like operation

paper echo
#

true, but im talking about times where the actual behavior of the @ binary operator is unpredictable and potentially very confusing

boreal umbra
#

It could be very confusing, yes

#

But I need it

paper echo
#

some people thought they needed @ to mean matrix multiplication, so here we are

#

believe me, i'd much rather it used for composition

boreal umbra
#

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.

radiant garden
#

Let's not forget the fact that string modulo as formatting is somehow commonly accepted

boreal umbra
#

@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.

half wolf
#

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 :(

true hollow
#

What's the difference between Python/ast.c and Python/Python-ast.c?

paper echo
#

@half wolf sounds like it's time to start using Hy

true ridge
#

What's the difference between Python/ast.c and Python/Python-ast.c?
@true hollow for 3.10, Python/ast.c contains 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

vapid slate
#

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?

boreal umbra
fringe tusk
#

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?

gloomy rain
#

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.

scenic flare
#

@gloomy rain

fringe tusk
#

I see!

#

Thank you very much :)

unkempt rock
#

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

flat gazelle
#

you could do it by crafting bytecode using something like hax

grave jolt
#

@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

glass sinew
#

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

swift imp
#

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)
paper echo
#

@swift imp i believe it sets the metaclass of ipaddress.IPv4Address to be IPv4v6Base

#

!d g abc.ABCMeta

fallen slateBOT
#
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)
paper echo
#

So I wasn't quite right

#

Not sure what it does now after reading the docs... not a great explanation in there

true hollow
#

Does the CI in the cpython repo really takes so long? isidentical made a push 3 hours ago and the circle is still yellow

radiant fulcrum
#

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

unkempt rock
#

?tag IndexError

zenith topaz
#

We dont'help with ytdl

#

!ytdl

fallen slateBOT
#

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)
sacred yew
#

@swift imp @paper echo lets you do isinstance when you dont control the subclass's code

swift imp
#

so the class you register comes back as True when doing isinstance(registered_class, abcMeta_class?

sacred yew
#

isinstance(registered,IPv4v6Base)

swift imp
#

Thanks

paper echo
#

so it makes isinstance work without the registered class actually inheriting other metaclass behavior

brave badger
raven ridge
#

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.

simple badger
#

anyone interested in group study for prep coding interviews?

raven ridge
#

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.

brave badger
#

ah, right

cloud crypt
#

yeah

inland juniper
#

k,j

runic musk
#

Does anyone know what __basicsize__ is?

wide shuttle
#

I don't think it's typically something you'd concern yourself with, but I'm not sure

true hollow
#

Where are PyNumber_And and PyNumber_InPlaceAnd defined? I used the GitHub search function and I couldn't find their definitions

true hollow
#

still can't find the definition

#

only the declaration and the proxy

torpid bridge
#

It's defined with a macro here:

true hollow
#

Omgggggggg thanks

#

And

#

How bin op works?

torpid bridge
#

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:

#

Integer is a false road, because python ints are uncapped and come from longobject.c

#

@true hollow hopefully that answers the question :P

true hollow
#

oh my God thank you so much 😄 😄

#

damn why did they make a thousand of references and definitions

torpid bridge
#

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

true hollow
torpid bridge
#

works-for-me?

true hollow
#

I can't click it :/

unkempt rock
#

It works

true hollow
#

I'm on mobile

unkempt rock
#

God, what is this mess

true hollow
#

it's a macro

#

and yeah

#

that's macro abuse

unkempt rock
#

No, I understand that. The pointers

true hollow
#

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

torpid bridge
#

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

true hollow
#

biggest code golf ever

unkempt rock
#

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

true hollow
#

I just wanted to add bitwise nand

#

foof

unkempt rock
#

Oh wait

torpid bridge
#

binaryfunc is defined with

typedef PyObject * (*binaryfunc)(PyObject *, PyObject *);
unkempt rock
#

Bruh, didn’t see parentheses there

torpid bridge
#

If you do, basically just copy the definitions and adjust as needed I'd bet

true hollow
#

By the way how long does it take to you to compile cpython? For me it takes 5 minutes

torpid bridge
#

Uh

#

around 5-10 for my laptop, probably much less for my desktop but never noticed having to

true hollow
#

It's mostly slow in the parser, ast, interpreter and objects

#

The unicodeobject takes years

torpid bridge
#

Yeah, you should see rusts syn crate ._.

true hollow
#

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 lemon_thinking

torpid bridge
#

wed have to write a bootstrapper

cloud crypt
#

I don’t like how python tree_macro!: ... looks like

true hollow
#

I don't think we need macros in Python at all

grizzled kraken
#

#bot-commands

radiant fulcrum
#

macros scare me

true hollow
#

same

spice pecan
#

Why not just do ~(a & b)?

true hollow
#

cpython-playground-atie

spice pecan
#

Fair point

true ridge
#

Hey @true hollow

true hollow
#

heya isidentical

true ridge
#

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
true hollow
#

yeah?

true ridge
#

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

true hollow
#

ahhh i understand

#

wait a sec

true ridge
#

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

true hollow
#

fair

true ridge
#

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

true hollow
#

hm okay

true ridge
#

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

true hollow
#

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?

true ridge
#

by the way, what's the name of this language?
@true hollow well, this is a custom DSL for our pegen (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)

true hollow
#

that explains why the plugin i installed for this file extension made the whole file be green

true ridge
#

lol

true hollow
#

are the any docs, or something (for this language)?

true ridge
#

yup

true hollow
#

yay

true ridge
true hollow
#

nice

#

well, it's building now

#

hope it works :p

true ridge
#

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

true hollow
#

nope, doesn't work

true ridge
#

nope, doesn't work
@true hollow interesting

#

let me check it out from my local computer

true hollow
#

sure

true ridge
#

it looks like is

#

did you regenerated the parser after changing the grammar?

blissful hornet
#

why this is advanced?

boreal umbra
#

@blissful hornet you're asking why this channel is called this?

blissful hornet
#

yp

boreal umbra
#

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.

magic python
#

does anyone make much use of the more-itertools module?

grave jolt
#

what about even-more-itertools

magic python
#

a lot of the methods there seem like something one would just write something custom for

#

oh what ha

grave jolt
#

never used either, though

magic python
#

seems dead

#

rip

#

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

feral cedar
#

itertools++

true hollow
#

@true ridge I always run make clean and then make when editing files related to grammar

true ridge
#

@true ridge I always run make clean and then make when editing files related to grammar
@true hollow you don't actually have to run make clean. Just make regen-pegen && make -j8 would be enough

true hollow
#

ahh okay

#

what's the j8?

true ridge
#

thread count

flat gazelle
#

honestly, I prefer to just make a separate function when doing more complex logic

true ridge
#

for compiling on multiple threads

magic python
#

@flat gazelle are you referring to the use of more itertools

flat gazelle
#

yeah

true hollow
#

conversation collision lemon_grimace

#

yay finally works

#

but unsupported operands :|

magic python
#

@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

true hollow
#

I'll try to fix this

true ridge
#

yay finally works
@true hollow congratz

true hollow
#

😄

boreal umbra
#

does anyone make much use of the more-itertools module?
@magic python I like the chunking functionality

magic python
#

@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

flat gazelle
#

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.

magic python
#

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

flat gazelle
#

unlike haskell, composition of recursion schemes in python just ends up in a mess

magic python
#

i couldn't think of an example for that

#

probably help if i knew what a recursion scheme was i guess

flat gazelle
#

just think of various smaller functions you compose to get the logic you want.

magic python
#

recursion isn't recursion in the sense of base case and all that jazz then?

#

you mean having nested list comps or what not

true hollow
magic python
#

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

flat gazelle
#

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

magic python
#

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

flat gazelle
#

yeah

unkempt rock
#

do you guys think the ++ operator can come to python some day?

#

i really miss it for increasing lambdas or comprehensions

spice pecan
#

probably not

unkempt rock
#

i know itertools.count is a thing, but anyways, i like the ++ syntax :P

cloud crypt
#

++ is pretty useless if you have += 1

#

or even simple range iterator

#

or count, in the end

#

!zen special

fallen slateBOT
#
The Zen of Python (line 7):

Special cases aren't special enough to break the rules.

spice pecan
#

There are very few cases when you really need ++, yeah

#

+= 1 and -= 1 are mostly suitable

cloud crypt
#

if you are not using ++ for its special and not really readable behavior, I don't see a point

grave jolt
#

AFAIK C++ also overrides ++ so that it acts as next for iterators

spark magnet
#

@unkempt rock how would you use ++ in a comprehension?

unkempt rock
#

well, thinking a bit about it, 95% can be done with ranges, so, that's true, the language shouldn't change because maybe 5%

spark magnet
#

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

hollow crane
#

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

wintry citrus
#

Besides, even if it wants in line callers and setters, python's new := could be thought to grow I'd say

loud summit
#

This channel is meant for discussing Python itself, not for general help @blissful hornet

blissful hornet
#

what do u mean python itself

loud summit
#

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.

blissful hornet
#

ok

safe hedge
#

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?

grave jolt
#

!pep 612

fallen slateBOT
grave jolt
#

yes

#

well, yes, but not yet

#

@safe hedge

safe hedge
#

Hmm

#

Type annotations always seem so promising but the effort involved to use them properly makes it so hard to want to use them

spark magnet
#

@safe hedge why does it need to be annotated? By definition it's a dict

safe hedge
#

Right. But I wondered if there was some way to say - these are the params for this other function

grave jolt
#

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):
    ...
safe hedge
#

And only half-annotating things seems worse than not annotating them at all imo

grave jolt
#

If it's something widely used, you could make a special Options object (a NamedTuple, for example)

safe hedge
#

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

grave jolt
#

well, yes

cunning oxide
#

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?

spark magnet
#

you want setattr(self, key, ...)

cunning oxide
#

yert omfg. Thank you. Lol.

spark magnet
#

but wouldn't it be easier to teach them how to subclass than how to use your unusual thing?

cunning oxide
#

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.

mossy heron
spark magnet
#

@mossy heron which regex pattern?

mossy heron
#

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.

#

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]
cunning oxide
#

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.

spark magnet
#

@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

mossy heron
#

Ahhh!! That's it. Thank you!

#

And thanks as well @cunning oxide I'll read that as well.

modern night
#

@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

crisp fulcrum
#

I have a question about subclass inheritance, which of these ways of making a subclass is better? Do they both accomplish the same thing?

spark magnet
#

light mode theme is better 🙂

crisp fulcrum
#

init in the subclass or just putting it in the parentheses of the subclass

spark magnet
#

The second one isn't a subclass. I would not do that.

crisp fulcrum
#

what is it?

#

sorry very new

spark magnet
#

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"

grand crag
#

And in case of inheritance, use super everywhere. (this would not even work in your example 2, I know)

crisp fulcrum
#

great the second one is from the python course im taking haha

modern night
#

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

spark magnet
#

@crisp fulcrum what course is that?

crisp fulcrum
#

it's been pretty good so far

spark magnet
#

yikes, that's disappointing

grand crag
#

Is it really written class Checking then in Checking.__init__, Account.__init__(self, filepath) ? 👀

crisp fulcrum
#

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
#

@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
@modern night Thank you! As mentioned earlier, I wanted to check if I can use something like func(a,b,*,c,d) along with *args and **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.

unkempt rock
#

Is that a course on basic things for 200 dollars?

crisp fulcrum
#

i think all udemy courses are way overpriced so they can sell you on 90% off sales... i got it for i think $12

unkempt rock
#

@crisp fulcrum How does an Udemy course differ from free Youtube videos?

viscid lintel
grave jolt
#

@mossy heron You can use / if you want to make arguments positional only

grand crag
#

but still the second __init__ was what i was confused about
If you understand what if self, then you understood the whole thing. It literally calls the Account's __init__ method, giving it as a self argument the new instance of Checking, meaning that the Account initializer will initialise the instance of Checking.

mossy heron
#

@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.

viscid lintel
north siren
#

ok

grave jolt
#

@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
mossy heron
#

Super cool! Thanks for sharing that!

crisp fulcrum
#

@grand crag wouldn't you be doing that everytime you make an instance of the Checking class?

grand crag
#

Each time a Checking instance is created, the Account's "constructor" is called with the newly created Checking instance as a self parameter.

bleak lantern
#

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

deft pagoda
#

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
shadow musk
#

oh wait, that's only in 3.9 😦

unkempt rock
#

what you guys think about functools.singledispatch?

raven ridge
#

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.

teal yacht
#

I don't understand why they went out of their way to implement singledispatch but not a multipledispatch version

#

it's so inconsistent

safe hedge
#

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?

deft pagoda
safe hedge
#

So just adding more arguments to dispatch on basically

deft pagoda
#

yep

bleak lantern
#

@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

teal yacht
#

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

deft pagoda
#

that's the point, yeah

#

some functions take a long while to compute

bleak lantern
#

thanks guys. i guess its a decorator that i should use more often!

feral cedar
#

it's not a guaranteed speedup, it's only useful in certain cases

zenith frigate
#

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

boreal umbra
#

@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.

rapid yew
#

pyoxidizer?

zenith frigate
#

okay @boreal umbra, thanks for opening help seeiosn 🙂

#

thanks @rapid yew , will check this one

boreal umbra
#

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.

zenith frigate
#

expecting a big changelogs of fixes in upcoming release of 3.9

#

as it happened earlier with 3.8

north root
#

@zenith frigate 3.9 was released the other week already

raven ridge
#

This was a reference to 3.9.1 I believe.

north root
#

ahh okay, that makes more sense

forest flicker
#

is python 3.9 backward compatible with 3.8? will it break 3.8 code after upgrade to 3.9?

feral cedar
#

no for the second question

safe hedge
#

I mean I don't think that's entirely true...

#

Stuff has been removed in 3.9

feral cedar
#

oh

safe hedge
#

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

boreal umbra
#

@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.

raven ridge
#

@boreal umbra that's semver that you're describing - semantic versioning. Python does not use semantic versioning.

boreal umbra
#

@raven ridge doesn't it use it... mostly?

raven ridge
#

"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.

boreal umbra
#

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?

sacred yew
#

doesn't semver only introduce breaking changes on major versions?

#

python does them in minors

#

@boreal umbra

boreal umbra
#

@sacred yew I thought breaking changes in Python were few and far between, but maybe I'm wrong

sacred yew
#

link welsh posted above?

#

and semver has no breaking changes in minors

safe hedge
boreal umbra
#

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

safe hedge
#

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

boreal umbra
#

I guess it would give them a clean slate as far as backwards compatibility goes

dense mauve
boreal umbra
#

@dense mauve that doesn't look like a complete question but take a look at the instructions on #❓|how-to-get-help

raven ridge
#

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.

raven ridge
#

To put it more pithily: versioning strategies like Python's are the problem that semver set out to fix.

shell needle
#

is this a good roadmap to learn python?

unkempt rock
#

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

#
shell needle
#

ok
Thanks I already know java upto opp.

unkempt rock
#

this is a really good resource to get you started

shell needle
unkempt rock
#

ok
Thanks I already know java upto opp.
@shell needle hey then you will have no trouble with python

shell needle
#

for this course I am learning python.

#

But I never done network and database with java.
so should I follow that roadmap?

unkempt rock
#

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

#

although refer to python docs before doing this cource

#

this will get you familiar with python syntax and all after which you can move on to whatever you want to do

shell needle
#

Thanks for your reply <3
I have already learn upto opp in python.

unkempt rock
#

thats cool

shell needle
#

shouild i learn networking with python next?

unkempt rock
#

dm me, mods here are strict

shell needle
#

@unkempt rock I am not a native english guy.
can u explain your last messege plzz

unkempt rock
#

wait i will message you personally. this group is is not for casual talk

blissful hornet
#

so why pip is not adding the installed moduels to PATH on linux

sacred yew
#

@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

blissful hornet
#

hmmm thank i will rry

#

try*

grave jolt
#

Why does str.join require the iterable to only have strings instead of calling str on each item?

flat gazelle
#

it would probably be somewhat error prone

grave jolt
#

huh?

paper echo
#

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

sacred yew
#

glares at php

stiff gust
#

class Sad:

#

def init(self,sad,depresed):

visual shadow
#

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.

undone hare
#

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

sacred tinsel
#

want to join strings? pass strings 🙃

pliant flame
#

Hmm you guys wanna do a quick help here?

boreal umbra
swift imp
#

Python generally tries not to convert types for you
@paper echo imagine having an iterable of DataFrames and trying to use str.join where it would first do str() 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

spice pecan
#

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

peak spoke
#

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

undone hare
#

imagine having an iterable of DataFrames and trying to use str.join where it would first do str() on each dataframe, that would be terrible
@swift imp doing str(d) for d in iterable instead of iterable is honestly not that bad

spice pecan
#

or map(str, iterable)

undone hare
#

This seems quite off-topic, this channel is for discussing the language itself

unkempt rock
#

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?

small tree
#

Hello. Good Afternoon.

#

someone has performance issue with matplotlib gui on windows 10?

undone hare
grave jolt
#

@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.

feral heath
#

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
flat gazelle
#

none

#

assignment alone just creates more names

feral heath
#

Can I .copy() implicitly then ?

flat gazelle
#

no

feral heath
#

Isn't there a way to do it if var2 is a class or something else ?

flat gazelle
#

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.)

feral heath
#

Could you please explain how I can override __builtins__ or redirect globals() ?

flat gazelle
#

again, neither of those would actually help.

feral heath
#

Ow.. too bad

#

Thank for explaining me this

elder lodge
#

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 ?

boreal umbra
#

@elder lodge someone in #databases might be able to help you with that

pseudo cradle
#

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
flat gazelle
#

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
pseudo cradle
#

Hmm, I didn't try a[3:] = [3]

#

I've just been doing uh....

#
a[3:] = repeat(3,len(a[3:]))
flat gazelle
#

oh wait, you do need that longer iterable

#

mb

pseudo cradle
#

Yeah 😦

#

Just another reason to like numpy and itertools

#

Since I think repeat works for any object

gleaming rover
#

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.

paper echo
#

@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

teal yacht
#

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

gleaming rover
#

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]
signal stratus
#

That's neat.

gleaming rover
#

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

signal stratus
#

Syntax is hard to grok at first.

gleaming rover
#

okay like conceptually

#

I would think that the first case is weird because you're replacing a subsequence with another of different length

pallid meteor
#

that is super weird looking

signal stratus
#

Replacing the range specified by the slice with the contents of another list.

gleaming rover
#

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"

signal stratus
#

It's [start:stop-1]

gleaming rover
#

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

signal stratus
#

You'd think it would put the other list in your list.

#

What if we wanted that?

gleaming rover
#

there should be a separate API for that

#

I will say, though, that I have never had a need for any of this

pallid meteor
#
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

signal stratus
#

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

pallid meteor
#

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

gleaming rover
#

it can take any iterable

swift imp
#

@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

teal yacht
#

yeah but lists are not meant to represent vectors

gleaming rover
#

^

swift imp
#

They're talking about numpy...

gleaming rover
#

They're talking about numpy...
@swift imp yes, but in the context of how list slice assignment should work

lucid mason
#

Hello, someone knows JavaScript?

gleaming rover
#

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.

lucid mason
#

@gleaming rover many tnx, i didn't see this channel

grave jolt
#

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

fallen slateBOT
#

:incoming_envelope: :ok_hand: applied mute to @unkempt rock until 2020-10-15 23:58 (23 hours and 59 minutes).

peak spoke
#

I'd guess it's mostly there because - is a thing

spark magnet
#

@grave jolt i think it's one of those things that is for numpy's use (and other things like it)

peak spoke
#

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 +

grave jolt
#

maybe it's just because C has it

#

🤷‍♂️

spark magnet
#

could be

sacred yew
#

just use abs

raven ridge
#

Could just be that it's a useful thing to have when using the language as a calculator

grave jolt
#

well, maybe it's useful when specifying deltas

#

like, change(-1) and change(+1)

raven ridge
#

Or accounting style tabulation.

peak spoke
#

There's really no downsides to having it around, even if it only has a few uses

grave jolt
#

well, yes

#

like @

peak spoke
#

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

radiant garden
#

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

peak spoke
#

88 seems a bit high even accounting for the docs, tests and definitions for numeric types and thing like the operator lib

#

Where exactly did you run it in? it's not perfect but github only got me 17 matches (I assume on master)

sacred yew
#

i count 22

#

on debian testing