#internals-and-peps

1 messages · Page 82 of 1

tidal marten
#

Writing something so massive from scratch would be futile

foggy juniper
#

Hi all, i would like to share a numpy array between multiprocessing. My intention is to take the frame after it's processsing to django view. Can anyone help on this?. i can share the numpyarray in threads, but in multiprocessing, i cant do it. Kindly help

undone hare
quiet wasp
#

hi guys, how are you? Lately I've been getting more and more curious about Domain Driven Design. Does anyone have experience with that in Python? I'm posting here since I think this is a rather advanced (or just uncommon) topic throughout Python users, but if more are interested in that maybe a #software-architecture/design channel would be worth it in the Topical Chat/Help section. However, I'd love to discuss the matter with anyone who knows about it, and maybe try and implement something together too!

outer prism
#

which cloud should I learn if i want to get into machine learning and ds?

undone hare
quiet wasp
#

I'm not asking for help, though, @undone hare 🤔

undone hare
#

Well, see the channel topic, this is about the implementation and the use cases of Python in particular, I’m not 100% sure if it fits the topic, maybe you could try in #python-discussion ?

quiet wasp
#

alright! How about the creation of a topical channel by the way? I mean something like #software-architecture/design where to discuss in general how to structure projects, who may decide if this could be a nice idea @undone hare ?

undone hare
#

We did have a channel like that, but it wasn’t very much used, kf you have any suggestion about the community though, feel free to send a message in #community-meta lemon_pleased

quiet wasp
#

thank you!

boreal rune
#

i've recently figured out how to use asyncio

#

is there a reason why there's no asynchronous range() function availible in the language?

peak spoke
#

What would be asynchronous in it?

boreal rune
#

it just seems strange to me that i'd have to implement something like that myself

#

oh well i can't do stuff like: -

#

WAIT NEVERMIND sorry

spice pecan
#

range just runs a simple calculation to get you an item at a certain index

boreal umbra
#

@spice pecan I didn't know range supported __getitem__--thanks!

olive marsh
#

can I get users liked pages/follower/(people followed) if I provide login using Twitter API?

spice pecan
#

It implements the Sequence ABC

boreal umbra
#

@olive marsh that question isn't on-topic for this channel.

desert peak
#

@olive marsh look at their API documentation and figure it out

#

@quiet wasp kind of sounds like appropriate discussion for this channel or #esoteric-python

#

#python-discussion seems to be focused purely on newbies and doesn't have very much fruitful conversation

#

anyone know if there has been work on compiling a list of 3.9-supporting frameworks?

mortal isle
#

l

unkempt rock
#

what is python if __name__ == "__main__" ?

#

I think I'm good enough with python but to this date I still have no idea what exactly it means, if anyone does please @

wide shuttle
#

@desert peak Thanks

desert peak
#

@unkempt rock It means if someone is invoking your script directly, like python -m app or python script.py

unkempt rock
#

or double clicking?

desert peak
#

correct

#

if you execute a script directly, its __name__ is __main__ instead of the module name such as import script or whatever

unkempt rock
#

ok so i understand it someone already answered it in #python-discussion but why do i see it in alot of code bases? from my understanding using it makes no sense ?

desert peak
#

because you might want your module to be executable, but you don't want the executable stuff to run on import

unkempt rock
#

what?

desert peak
#

there might be usable functions you want to import from your script, but you also want the script to run from the cli

unkempt rock
#

ohhh

#

i see.

desert peak
#

and without that block

unkempt rock
#

thank you very much

desert peak
#

it would run that code whenever you import it

unkempt rock
#

ye i get it now thanks, will prolly be using this lots now

desert peak
#

it's a good practice to add it so you don't accidentally execute usercode on imports

inland acorn
#

!if-name-main there is also a tag for it 😄

fallen slateBOT
#

if __name__ == '__main__'

This is a statement that is only true if the module (your source code) it appears in is being run directly, as opposed to being imported into another module. When you run your module, the __name__ special variable is automatically set to the string '__main__'. Conversely, when you import that same module into a different one, and run that, __name__ is instead set to the filename of your module minus the .py extension.

Example

# foo.py

print('spam')

if __name__ == '__main__':
    print('eggs')

If you run the above module foo.py directly, both 'spam'and 'eggs' will be printed. Now consider this next example:

# bar.py

import foo

If you run this module named bar.py, it will execute the code in foo.py. First it will print 'spam', and then the if statement will fail, because __name__ will now be the string 'foo'.

Why would I do this?

• Your module is a library, but also has a special case where it can be run directly
• Your module is a library and you want to safeguard it against people running it directly (like what pip does)
• Your module is the main program, but has unit tests and the testing framework works by importing your module, and you want to avoid having your main code run during the test

unkempt rock
#

wow

desert peak
#

not sure I'd word it "has a special case" - it's pretty common @inland acorn

unkempt rock
#

is theres a documentation for this bot?

desert peak
#

#bot-commands

inland acorn
#

it is open-source, and there is the !help and !tags commands

#

not sure I'd word it "has a special case" - it's pretty common @inland acorn
@desert peak feel free to open an issue on github if you think it should be reworded

unkempt rock
#

btw

#

you can eval stuff using the bot

mint forge
#

!source in #bot-commands @unkempt rock

unkempt rock
#

how is this secure?

#

i know theres probably checks and stuff but im also sure theres a bypass since you're running untrusted code

#

idk

#

just thought i'd point it out

inland acorn
radiant fulcrum
#

It's a Jailed python instance that is limited to a set of modules

north root
#

only one person has been able to break it

feral cedar
#

storytime?

north root
#

and we've patched that already

unkempt rock
#

oh wow

radiant fulcrum
#

Its basically you Vs Google

north root
#

yep

unkempt rock
#

It's a Jailed python instance that is limited to a set of modules
@radiant fulcrum limiting the modules is useless and shouldn't be count as security

radiant fulcrum
#

I mean it is because it limits what you can do lol

north root
desert peak
#

how is the bot hosted? some VPS?

unkempt rock
#

you can still rewrite the modules inside the eval'd code using python without any modules

north root
#

we're sponsored by linode

radiant fulcrum
#

linode vps yeah iirc

desert peak
#

ah, very nice

flat gazelle
#

we don't really limit the modules, do we?

radiant fulcrum
#

you get access to a certain set

#

not all

#

but most

desert peak
#

!e

import os

print(os.system('ls'))
fallen slateBOT
#

You are not allowed to use that command here. Please use the #bot-commands channel instead.

north root
#

you can use the whole stdlib and the extra modules we've installed

peak spoke
#

There's no module restrictions, some are just useless in the restricted environment; but this seems more fitting to #community-meta

unkempt rock
#

off-topic but what does meta mean lol

radiant fulcrum
#

the actual security side of it is Down to NSJail

#

the discord itself and the things related to it

unkempt rock
#

hi

radiant fulcrum
#

see the topic in meta

desert peak
#

@unkempt rock meta means referring to self, such as us talking about discord and the channel itself and not Python

unkempt rock
#

ah ok

#

i would assume if someone is aiming to mess with the eval they wouldnt actually break the sandbox rather they'd mess with results that the bot will take and display in channel

#

i cant say @ everyone? i mean its disabled why i cant say it -_-

flat gazelle
#

there was an incident where the ping got quoted by someone who could

radiant fulcrum
#

its returned in a embed block and also now is escaped

desert peak
#

"an incident" LOL

inland acorn
#

we have a check for code block escapes, and the result is run thru our normal chat filters

radiant fulcrum
#

it wasnt from the eval though

#

Error handling on a different command went ping pong

unkempt rock
#

we have a check for code block escapes, and the result is run thru our normal chat filters
@inland acorn ye i know but there must be a bypass, im 100% sure a string wizard can bypass it

desert peak
#

Can you @ user IDs?

#

oof, getting off-topic here

unkempt rock
#

saying a thing or two off topic shouldnt be a crime lol otherwise you would need to end each message with "this is an advanced discussion :)"

odd ether
#

ye i know but there must be a bypass, im 100% sure a string wizard can bypass it
@unkempt rock You're encouraged to try and break out (and then tell us how you did it)

north root
#

alright, this whole conversation has been off-topic, to be fair

unkempt rock
#

how? its python related lool

odd ether
north root
#

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.

unkempt rock
#

ah ok

desert peak
#

anyone think the macro or pattern matching PEPs get adopted for py310? they seem controversial. I also want null syntax

#

those three things would make python much more ergonomic to me

silk pawn
#

Are there any current optimization projects for the stdlib that have an idea in mind of what to change, but the person in charge doesn't have the time to do it?

#

Like how a ton of built in functions were migrated to PEP 590(?) vectorcall calling conventions, but that's still going on on 3.8, 3.9, and 3.10a1 iirc, so I'm wondering if there are optimization projects that need extra manpower/womanpower to finish, but have a clear idea of what they're trying to optimize

icy tartan
#

Greetings, is there a version of multiprocessing.Pool.starmap that returns an iterator like multiprocessing.Pool.imap and multiprocessing.Pool.imap_unordered do?
It's not crucial, but my tqdm-progress bar depends on it!

boreal umbra
icy tartan
#

@boreal umbra ah, thanks. Based on the channel name I expected it to be only about async, not all other forms of concurrency. I stand corrected now that I actually looked at the channel description 🙂

#

Meanwhile I worked around my issue (in not the most beautiful way) by just rewriting the function to take one argument and unpacking it on the first line.

glass robin
#

What’s the controversy about pattern matching? I understand the one over macro, and I even doubt they would be userull in python

cloud crypt
#

some think it brings more problems than it solves

#

anyways, I got a small design question, basically I have a classic Point class with x and y fields, with overloaded addition to support adding coordinates of points

#

what should I use for isinstance check there?

#

isinstance(other, self.__class__) or isinstance(other, __class__)?

deft pagoda
#

self.__class__ or type(self)

unkempt rock
deft pagoda
#

Let's pretend we're building some library, a graph library, say, but you want the library to be agnostic to whether one uses a networkx.Graph, graph_tool.Graph, or igraph.Graph underneath it all. To accomplish this you build some "universal" Graph that provides a consistent interface to all three Graphs. We don't want to litter the start of each method with a conditional that checks which module we're using -- what we'd like to do instead is set our method the first time it's called to interface with the correct module. So how best to accomplish this? This is a rough draft of what I'm thinking: https://gist.github.com/salt-die/ac6b7e75df258bdd4cff6e259ee50909 . This hack is a decorator/descriptor for each method we intend on implementing. My feeling is that there's something simpler one could be doing also involving descriptors.

Gist

how best to provide a consistent interface to similar objects across multiple modules? - graph.py

stone mauve
#
import random
from random import choice
list = ['Luis', 'B', 'C']
winner = choice(list)
print(winner)

@unkempt rock you don't need to type random.choice just choice because of how you imported it

desert peak
stone mauve
#

Is it frowned upon to use os.system() to run shell commands? sometimes there's just an easier way to do something with the shell and it's handy to have it in the python file.

shy saddle
#

Shot in the dark... Has anyone used python to create images in GIMP?

desert peak
#

!docs subprocess.run @stone mauve

fallen slateBOT
#
subprocess.run(args, *, stdin=None, input=None, stdout=None, stderr=None, capture_output=False, shell=False, cwd=None, timeout=None, check=False, encoding=None, errors=None, text=None, env=None, universal_newlines=None, **other_popen_kwargs)```
Run the command described by *args*. Wait for command to complete, then return a [`CompletedProcess`](#subprocess.CompletedProcess "subprocess.CompletedProcess") instance.

The arguments shown above are merely the most common ones, described below in [Frequently Used Arguments](#frequently-used-arguments) (hence the use of keyword-only notation in the abbreviated signature). The full function signature is largely the same as that of the [`Popen`](#subprocess.Popen "subprocess.Popen") constructor - most of the arguments to this function are passed through to that interface. (*timeout*, *input*, *check*, and *capture\_output* are not.)... [read more](https://docs.python.org/3/library/subprocess.html#subprocess.run)
stone mauve
#

@desert peak that's nice to know. Most of the time though I'm just running something simple or in my local bin and usually have os imported so this seems a little heavy for what I do. Thanks for telling me about this though.

boreal umbra
#

Is this a true statement that I wrote?

when people talk about "imperative programming", "object-oriented programming", etc, they're talking about general approaches to language design that can inform the design of a given language to varying extents.

desert peak
#

🤷🏽 I'm not sure I would contrast "imperative" alongside "object-oriented" @boreal umbra

#

Imperative vs. Declarative are approaches to programming. One states you use the language to instruct each stage of the way, the other states you say what you want and the language figures out the implementation details

boreal umbra
#

@desert peak I'm not contrasting specific "x programming" terms, I'm referring to the idea of "x programming" in general.

crystal kindle
#

hey all

#

high level play thing ready for tinkering

#

this is win64 - prototype

#

hook into actions in game engine is polling

#

import bpy
wm = bpy.context.window_manager
value = wm.xr_session_state.get_action_state(bpy.context, "action_set_name", "action_name", "/user/hand/left#path")

raven ridge
#

Is this a true statement that I wrote?
@boreal umbra I'd agree with that.

boreal umbra
#

I remember Guido said in an interview that python isn't intended to be a functional programming language, but I don't think he or anyone else contests that functions are a core component of the language

#

So I interpret that statement to mean that functional programming just wasn't the paradigm that he prioritized.

raven ridge
#

"functions" and "functional programming language" are relatively unrelated

#

C has no functional features whatsoever, but has functions, after all

#

the feature that Python has that's most strongly correlated with functional programming languages is probably functions as first order objects. That's a feature that Python has, and that's rare outside of functional languages.

sacred yew
#

@crystal kindle wrong channels

#

don't a lot of mainstream langs have functions as first-order objects?

#

js has it

#

java and c++ have lambdas now?

raven ridge
#

Java and C++ have lambdas, but neither of those have functions as first order objects.

#

C++ lambdas are functors, not functions - they're class instances, not functions.

#

Likewise for Java, I believe.

#

Yeah, Java's the same, from quick googling.

#

C++ also lets you pass pointers to functions around - but that's not quite the same thing as passing functions around.

sacred yew
#

lua perl php swift rust go julia according to wikipedia

coral tree
#

Is PyCharm Edu just PyCharm Community with the EduTools plugin?

gleaming rover
#

Is PyCharm Edu just PyCharm Community with the EduTools plugin?
@coral tree this is a channel for language discussion; you might want to try #tools-and-devops. thanks!

mint forge
#

not the channel

weary minnow
#

how can i access the "vscode" key itself without knowing the name

#

in the sense like i want to access the second object inside the json

#

i want to get the "vscode" as the key for the json

unkempt rock
#

Hi guys i am shrivardhana,I am in 7th grade,I am very interested in python.i finished my python course last week.i am looking forward to do my first project

mint forge
#

!projects @unkempt rock and wrong channel

fallen slateBOT
#

Kindling Projects

The Kindling projects page on Ned Batchelder's website contains a list of projects and ideas programmers can tackle to build their skills and knowledge.

unkempt rock
#

!projects @unkempt rock and wrong channel
@♦ Inheritanc-e#1090 👍

muted crane
#

I've always had this question

#

Why do we have PEP 8?

amber nexus
#

To keep things consistent

undone hare
#

Because standards = good

#

Having the same style accross every code bases is very useful

muted crane
#

You can choose to make your code more readable than to follow a standard

#

Less effort reading the code in my opinion

undone hare
#

Also copying code from one code base to another is really easy

visual shadow
#

You can choose to make your code more readable than to follow a standard
@muted crane the issue is, what's readable for you might not be for someone else. And that leads to fragmentation. It's a lot nicer for everyone to agree on one standard as best possible.

#

As always, there can be cases where you might have to deviate. One rule i commonly flout is the max characters in one line rule.

#

But by and large, trying to conform to a standard helps everyone

muted crane
#

So I don't have to follow it strictly

visual shadow
#

But you should as best possible.

#

Because just imagine this very moment. You're unwilling to learn the standard because "it's slightly different from what you prefer.". In avoiding this step, you're creating this very same problem for everyone else who now have to figure out your way of doing things.

#

This is why standards help. Consistency helps everyone. And if a standard itself is bad, it should be challenged accordingly.

muted crane
#

I see

visual shadow
#

I do have a suggestion to ease the transition. Most modern editors have some kind of code linter or style analysis

#

Just turn it on, and eventually your warning messages will annoy you enough that you'll do something about it 😅

muted crane
#

I heard of those

undone hare
#

Most IDEs can also automagically format your code

visual shadow
#

I personally didn't learn about standards when I started coding. So I had to go through this transition phase too. Just finding that setting on my editor made it super easy.

warm tulip
#

warning messages anoying

muted crane
#

It sounds harder to code with these settings in addition to the problems you face in the code itself

undone hare
#

I don’t find it harder once you’re used to those

#

Besides, most of them have a reason, and will help you further down the road

#

For example the “attribute assigment out of __init__” in PyCharm can help you catch some nasty bugs

visual shadow
#

Honestly, pep8 standards are really well thought and designed

#

I just didn't know about them enough to appreciate it till I had the warning messages staring me in the face.

flat gazelle
#

what is just silly is demanding sorted imports, but most linters do not do that

warm tulip
#

i think i will configure my linter to use pep8 standards

#

It will help me in the future, I think

muted crane
#

Yeah, might do that too

visual shadow
#

Hands down my most favourite one is white spaces around operators.

warm tulip
#

yes

flat gazelle
#

you generally have the formatter do that

warm tulip
#

that is good

#

that is very good

muted crane
#

It's neat, yeah

visual shadow
#

It's one I used to get wrong. It really helped code readibility. (and had the side effect of reducing my tolerance for code that doesn't have these whitespace)

warm tulip
#

what is sorted imports

#

that sounds harsh

#

is that like import sys, os

muted crane
#

I only use whitespaces, but still do imports on the same line

#

Same for variable assignments

undone hare
#

The line limit is worst than he sorted imports IMO

#

Besides, I am a weirdo and I like sorted imports

flat gazelle
#

yeah, line limit is also not all that great

muted crane
#

It's 24 columns right?

cloud crypt
#

line_limit = 100 or I won’t participate in your project :p

flat gazelle
#

80 cols, 24 would be impossible

cloud crypt
#

79

flat gazelle
#

but generally people go for 100-120

muted crane
#

Sounds better

flat gazelle
#

the only reason for 79 are old 80 wide terminals, but that is not relevant in 2020

warm tulip
#

pep8 sounds harsh

muted crane
#

Why would they put a line limit?

flat gazelle
#

overly long lines are bad indeed

warm tulip
#

they are

muted crane
#

At least the code is readable, following all other standards

warm tulip
#

very bd

cloud crypt
#

if I were reading someone's code I'd rather have to scroll in one direction only

warm tulip
#

yes

#

ok

radiant garden
#

I tend to keep my code thin, but sometimes pop in a one-line double-nested f-string lambda lambda double listcomp for fun

muted crane
#

Wrong channel btw

flat gazelle
#

but also, self.adults = [member for member in all_members if member.is_of(self) and member.age > 18] is really no worse than

self.adults = [
    member
    for member in all_members
    if member.is_of(self) and member.age > 18
]
cloud crypt
#

is_of? heh

radiant garden
#

yeah I never was able to get multiline x-comps to "feel" right

brave badger
#

Vertically-spaced code is both meh and alright I guess

cloud crypt
#

I’d rather put ... for ... in ... on one line

muted crane
#

It feels weird to code a list comp like this tbh

warm tulip
#

I prefer my 300 character line python programs

#

tbh

cloud crypt
#

since it doesn’t make much sense to give an additional line

#

but honestly my code standards are the weirdest

flat gazelle
#

I generally just write things and run black and isort and autoflake on it

cloud crypt
deft pagoda
grave jolt
#

I would say that generally, shorter lines are better, but breaking a line into multiple lines just to satisfy the line length may reduce readability

warm tulip
#

what does it do

flat gazelle
#

that is pretty

#

but yeah, pep8 does not like aligned :

warm tulip
#

Terminal was blocked on my school's iMac, so I used AppleScript to execute shell scripts instead

#

lmao

radiant garden
warm tulip
#

no reason

#

i can see none

#

flawless code

grave jolt
#

but yeah, pep8 does not like aligned :
Even though CPython's source code does use alignment like that
and often they're screwed up in some place lemon_enraged

warm tulip
cloud crypt
#

CPython's STD is non-PEP8 as hell

undone hare
#

CPython is pretty much not PEP8 compliant haha

grave jolt
warm tulip
#

lmfao

flat gazelle
#

well, it does predate pep8 and changing it is not exactly easy

radiant garden
#

hey, it gets the whitespace right

flat gazelle
#

supposedly the PRs often introduce bugs

warm tulip
#

ah

cloud crypt
#

hold up

#

imagine

warm tulip
#

or they are too lazy

cloud crypt
#

black on Lib/

#

lul

undone hare
#

It would be... fun haha

cloud crypt
#

I’ll fucking do it

warm tulip
#

i once made a fake "Downloading Windows" program that made a progress bar appeared and my computer lab teacher got spooked

muted crane
#

Wait what does black do?

flat gazelle
#

ast comparison taking hours

muted crane
#

Enforce pep8?

undone hare
#

Yes arven

#

And yeah, it will probably run for hours haha

warm tulip
#

pep8 is great (don't send hate!)

cloud crypt
#

I doubt compiling rust will be faster than running flake8 on library

warm tulip
#

ryme

#

rime

cloud crypt
#

also akarys I’m working on braces.py again lol

flat gazelle
#

being faster than compiling rust is a really low bar

warm tulip
#

what is ast comparison

#

is that like a render on steroids

cloud crypt
#

no?

flat gazelle
#

black, in order to ensure it did not screw anything up, checks if the ast of what it outputs is the same as the input ast

cloud crypt
#

it basically checks if formatted code produces same AST

warm tulip
#

checksum?

cloud crypt
#

as unformatted code

#

no

warm tulip
#

oh

cloud crypt
#

AST comparison is recursive soooooo

warm tulip
#

oh

#

oh no

#

thats gonna take a while

flat gazelle
#

you don't really need recursion to compare trees, but IDK if black uses recursion

cloud crypt
#

what is STD at, 250k lines?

muted crane
#

250k lines???!!

warm tulip
#

thats a lot of CODE

#

how long did that tak

grave jolt
#

Long-standing question from me: doesn't automatically PEP8'ing code break PEP8? Because of the "A Foolish Consistency is the Hobgoblin of Little Minds" section

muted crane
#

Enforcing pep8 into code can be breaking as far as I concern

undone hare
#

also akarys I’m working on braces.py again lol
@cloud crypt oh no

flat gazelle
#

yes, it can, which is why you write and test with pep8 already enforced

warm tulip
#

uhhh

#

uhhh

#

oh no

cloud crypt
#
C:\Users\nekit\OneDrive\Desktop\coding\cpython>black Lib --line-length=79```
#

oh no

#

lol

warm tulip
#

what have you done

cloud crypt
#

FUCK it'll do site-packages as well

muted crane
#

Lol

cloud crypt
#

I am at /http/ already

flat gazelle
#

well, see you in a few hours

muted crane
#

That might take a while

cloud crypt
#

yes

warm tulip
#

ok i go goodbye

#

see y

#

a

muted crane
#

^ pep8 in action right here

cloud crypt
#

/test/ already

muted crane
#

post traumatic pep8 disorder

#

Why did you do it though?

undone hare
#

test will take a while

cloud crypt
#
error: cannot format C:\Users\nekit\OneDrive\Desktop\coding\cpython\Lib\test\bad_coding.py: unknown encoding: uft-8
error: cannot format C:\Users\nekit\OneDrive\Desktop\coding\cpython\Lib\test\bad_coding2.py: encoding problem: utf-8``` haha
#

funny

undone hare
#

Haha

muted crane
#

Did someone challenge you to use black on CPython libs?

cloud crypt
#

no

#

I did it anyway

muted crane
#

Oh good god

cloud crypt
#

almost the end of the /test/

#

graphlib is apparently PEP8-compliant

#
1590 files reformatted, 117 files left unchanged, 7 files failed to reformat.```
undone hare
#

Is it done?

cloud crypt
#

yes.

#

I got a nice laptop so

undone hare
#

git diff | wc -l now

cloud crypt
#

windows

undone hare
#

F

#

install GNU utils

cloud crypt
#

OH MY FUCKING GOD

#
1590 files changed, 277192 insertions(+), 192645 deletions(-)```
undone hare
#

Hahaha

cloud crypt
undone hare
#

+8k lines

brave badger
#

I do not like that ratio

cloud crypt
#

now

#

I'm gonna run flake8

#

aifc, argparse and ast are only ones broken

#

and abc

#

also someone used bare except

undone hare
#

Now python -m test

cloud crypt
#

oh boy

#

how do I use threads there

undone hare
#

make test -j4 maybe?

cloud crypt
#
test_dict -- test_opcodes failed``` huh
#

AH

#

I know why

#

imagine basing your tests off of non-PEP8-compliant code

#

there are more but I see

unkempt rock
#

nekit is exposing the spaghetti toothpicks that python relies on

#

never expose the masters like this nekit!!!

tough narwhal
#

Someone here who knows, how to use pyautogui?

desert peak
tough narwhal
#

thnx

south kelp
#

Hello

desert peak
#

RE: formatting CPython - I do not like Black.

#

I think its rules are wrong - prefer yapf

#

I wish these highly adopted frameworks would reach a non-beta state, though

undone hare
#

I also dislike Black's style

#

But it is just a matter of personal preferences

desert peak
#

then again, I prefer using tabs in my personal projects with spaces for alignment which linters hate

undone hare
#

Ah welp

desert peak
#

thankfully flake8-tabs exists

#

it lets me have my own preference on indentation levels without impacting others @undone hare

undone hare
#

Interesting, how does it work?

desert peak
#

you use tabs for X level of indentation, but if you have a hanging indent for parameters or something, those will be spaces.

some_fn_call(par1,
             par2,
             par3)
# ⬆ spaces

def fn():
    call_thing()
    return 5
# ⬆ tabs
#

I'm still figuring out how to auto-format in this way using yapf, but it's my goal. my vscode config looks like this:

        "editor.detectIndentation": false,
        "editor.insertSpaces": false,
        "editor.renderControlCharacters": true,
        "editor.renderWhitespace": "boundary",
        "editor.rulers": [80, 100],
flat gazelle
#

not sure how much I like mixing space and tab like that

#

oh, discord converts the tabs in the msg

desert peak
#

oh derp

#

I even explicitly inserted tabs

heady mauve
#

With multiprocessing, does one process slowing down (more data to work with) affect other processes?

desert peak
#

it can, yes

mellow widget
#

!resources

fallen slateBOT
#
Resources

The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.

hoary shore
#

How random is the random module?

peak spoke
#

It uses the Mersenne Twister random generator

desert peak
#

the answer is usually: "random enough"

cloud crypt
#

but not secure

#

and Mersenne Twister is meh on its own

desert peak
#

@cloud crypt I don't think security matters. People who implement their own crypto have enough knowledge to use the secure forms of entropy.

wide shuttle
#

and Mersenne Twister is meh on its own
@cloud crypt

What do you mean by that? It's used a lot in simulations and statistical modeling.

cloud crypt
#

let me find a nice table of comparison

#

to begin with, it has a relatively large state buffer (2.5 KiB), is not cryptographically secure, and can take a while to start generating numbers that pass randomness tests

#

so yeah, we can just say random enough

wide shuttle
#

Well, sure, so don't use it for crypto

#

What I meant was, the Mersenne Twister is still used a lot in mathematical and statistical simulations and computations

fresh cargo
#

Well, it said on its doc "The pseudo-random generators of this module should not be used for security purposes"

wide shuttle
#

There's some discussion as to whether or not we should switch to other random number generators, but your review of the Mersenne Twister seems a bit one-dimensional.

cloud crypt
#

alright, I should mention advantages, then

sacred yew
#

iirc mt is slower and requires more memory than other prngs

cloud crypt
#

It has a huge period of 2^19937, which is nice but not something to really aim for

sacred yew
#

advantages are that its widely used

cloud crypt
#

and k-dimensional equidistribution

wide shuttle
#

My simulation studies have never been limited by the large memory state or speed of the Mersenne Twister

cloud crypt
#

indeed it’s not like

wide shuttle
#

It's widely used and accepted in academic circles, and has decent properties for most simulations

cloud crypt
#

a bad PRNG

wide shuttle
#

However, there may be newer, better alternatives now

cloud crypt
#

but there are better alternatives

#

yeah, exactly

wide shuttle
#

Well, it's by no means said that those alternatives will become new standards like the MT is

#

In academia, that is

sacred yew
#

what do other mainstream languages use?

#

i think v8 uses xorshift128+

#

java uses some shitty lcg

fresh cargo
#

C++11 is also Mersenne Twister I believe

#

Or maybe it's one of the available ones

desert peak
sacred yew
#

i think glibc uses a lcg also

desert peak
magic python
#

just bothered looking up alternative approaches to setup.py bc everyone says setup.py is the old way and i can't do basic things like pip install -e if I use toml 😩

#

why is packaging such a shit show

desert peak
#

That is not true

#

But yes, packaging is a terrible wart on Python

magic python
#

oh

pyproject.toml" file was found, but editable mode currently requires a setup.py based build.
maybe i've missed something

desert peak
#

it sounds like your version of pip is outdated or you're using the wrong flags

#

or setuptools

#

``sh

magic python
#

pip is > 20, python 3.8, flags - just pip install -e <pkg> , setuptools I'm not familiar with, if it sounds like there's something obvious i should read let me know

desert peak
#
$ python -m pip install -U pip setuptools
magic python
#

already had 47.1 installed

desert peak
#

it's on v50+ now

magic python
#

😊

#

upgraded, doesn't work

desert peak
#

what does your pyproject look like?

magic python
#

the toml file?

desert peak
#

yes.

magic python
desert peak
#

oh, you're using poetry

#

why are you trying to pip -e?

#

just do poetry install

magic python
#

why are you trying to pip -e?
no idea, just thought that's how i installed something in editable mode

desert peak
#

nope, poetry installs your package into the venv automatically

#

in editable mode

magic python
#

only messing around with poetry for the first time

sacred yew
#

doesn't poetry have its own method

#

to install into dev

desert peak
#

indeed

magic python
#

what if i want to give poetry a path?

sacred yew
#

wait doesn't poetry put it in the venv already

magic python
#

well i have a package, which has a venv, and i want to install that package in another project with a different venv

sacred yew
#

but this is the wrong hcannel

desert peak
#

@magic python if that's the case, then you build and distribute it

magic python
#

god i hate this too

desert peak
#
poetry build -f sdist
magic python
#

i'm just going to use setup

desert peak
#

I can't help that your dev process is weird 🤷

#

why would you want multiple packages installed in editable mode?

magic python
#

no worries, at least setup.py does what i expect without magic i don't care if i type a few more lines

desert peak
magic python
#

: )

desert peak
#

You just don't want new magic

magic python
#

no i don't

boreal umbra
#

if you do pip install -U some_module>=3, and you have version 4 installed, but version 5 exists, will pip not upgrade you to 5?

desert peak
#

Looks like no

boreal umbra
#

@desert peak what's the point of asking people on the internet if I have to read stuff?

#

jk, I didn't know about this pep. Thanks!

static hull
#

Can someone tell me if there is something like automated message on chat after joining the meeting on Teams?

mint forge
#

not the channel

static hull
#

where then?

undone hare
#

!offtopic this would be the proper way to ask

fallen slateBOT
thorny nimbus
#

Which is better performance
zip(itertools.count,iter) or enumerate functions interms of performance

flat gazelle
#

probably enumerate

thorny nimbus
#

probably enumerate
@flat gazelle Thanks for the fast reply

boreal umbra
#

the real question is when you want to zip multiple iterables and also enumerate them

deft pagoda
#

you can zip with a count object if you don't want to wrap enumerate around it all

#

oh, i guess i should've read a few lines up

#

i would probably still enumerate even if i was zipping a other iterables

boreal umbra
#

you have to do

for i, (a, b, c) in enumerate(zip(d, e, f)): ...
#

kinda kills the elegance, but is still better than rangelen

spice pecan
#

I think it conveys the purpose a lot better tbh

boreal umbra
#

@spice pecan conveys it better than rangelen? yes, by a million years, because then all the items you're iterating over are stated and not just one. The parens are weird for me though.

spice pecan
#

No, as in enumerate(zip(...)) conveys the idea better than zip(itertools.count(), ...)

#

rangelen being doodoo is a separate topic, though I do agree wholeheartedly

desert peak
#

I mean, the parens are just unpacking

#

you could do for i in enumerate()

unkempt rock
#

double quotes or single quotes?

silk coyote
#

double quotes or single quotes?
@unkempt rock it only depends on the string content, if you want to include in the string a single quote, you need to use double quotes, else if you need to include a double quote you need to use single... there are really no other differences

unkempt rock
#

@silk coyote righto

cloud crypt
#

I prefer double quotes for most stuff

spice pecan
#

I do single most of the time, that feels like the "default" version to me

cloud crypt
#

the other way around here

#

well I preferred single previously but then

#

idk

spice pecan
#

I do see the merit in double quotes for consistency with other languages

cloud crypt
#

yeah that kind of thing as well

#

I’ve had troubles accidentally writing 'string' before

spice pecan
#

I mostly stick to single as a habit, it's consistent with repr and adds less visual noise

deft pagoda
#

i often switch between ' and " as I switch projects

unkempt rock
#

I wonder about dictionary lookups and increments, while checking for keys' existence:

#
substrings[substring] = substrings.get(substring, 0) + 1
#

I generally use the pattern above to autoincrement a value associated to a dictionary key, whether it's missing or not.

#

The one thing that bothers me is that I suspect it performs two lookups.

#

Is that actually the case?

#

When I am performing an operation on a mutable object I can rely on setdefault() which returns the object. I can't do that with immutables though.

#

In C# one uses an out variable to refer to the value one changes:

boreal umbra
#

@unkempt rock couldn't you use defaultdict?

unkempt rock
#
dict.TryGetValue(id, out var currentCount); 
dict[id] = currentCount + 1;
#

@unkempt rock couldn't you use defaultdict?
@boreal umbra Yes. In this case I am limited to built-ins though.

boreal umbra
#

why

unkempt rock
#

Uni assignment.

boreal umbra
#

I hate that.

unkempt rock
#

Yes, I understand. 🙂

undone hare
#

It does perform two lookups, yeah

#

Although using a defaultdict and a += would have to perform one lookup and one assignment (because int is unmutable), which is pretty close to a lookup in term of complexity

#

So it is almost the same thing

#

Just way too much verbose, like any uni assignment

#

__import__('collections').defaultdict only use builtins though

#

Hehe

unkempt rock
#

Thanks for the answer, @undone hare!

undone hare
#

Anytime!

unkempt rock
#

(it's likely they will check the builtins globals for anything imported, in unit tests :-))

undone hare
#

Oh god, if it is unit tested, there sure are ways to bypass it

cloud crypt
#

ah yes

flat gazelle
#

you could also just make your own defaultdict, since I don't think they will care about performance. Consider dict.fromkeys though

cloud crypt
#

__import__

flat gazelle
#

if you already know what keys you will need, dict.fromkeys(l, 0) is better than defaultdict

unkempt rock
#

Oh god, if it is unit tested, there sure are ways to bypass it
@undone hare Yes, I am almost certain. I am being an honourable schoolboy though, so far.

undone hare
#

Haha, fair enough

flat gazelle
#

you can bypass most unit tests with type('',(),dict(__eq__=lambda*a:True))()

still hamlet
#

i have a doubt in pycharm

#

can anyone help me

flat gazelle
undone hare
#

That's so true lak haha

desert peak
#

isn't defaultdict a builtin?

#

well, built into the stdlib 😉

flat gazelle
#

defaultdict is part of the standard of the standard lib, but it is not part of the builtins module

unkempt rock
#

if you already know what keys you will need, dict.fromkeys(l, 0) is better than defaultdict
@flat gazelle Thanks. I am generating keys as I go though, so can't default-add all of them. Nice thinking though.

cloud crypt
#

@flat gazelle what about raising errors

flat gazelle
#
raise type('',(Types,To,Raise),{})()
``` unfortunately, `Exception.__subclasses__()` is unviable
fallen slateBOT
#

:incoming_envelope: :ok_hand: applied mute to @ripe cobalt until 2020-11-05 18:58 (9 minutes and 59 seconds) (reason: duplicates rule: sent 5 duplicated messages in 10s).

spark parcel
#

<@&267629731250176001>

smoky vessel
#

omg that was inapropriate

wide shuttle
#

Let me have a look

spark parcel
#

NSFW image spam

smoky vessel
#

they deleted it immeditely tho

north root
#

!ban 491716476764553216 NSFW images spam

fallen slateBOT
#

failmail :ok_hand: applied ban to @ripe cobalt permanently.

spark parcel
#

Anti-spam filter @smoky vessel

smoky vessel
#

ye

#

ok cool problem dealt with thx everyone

delicate ermine
#

any best practices for developing packages locally? I.e I'm in an enviroment where I every everything but somepackage installed. I want to test out functionality of someModule inside codeToTestPackage.py. I don't want to add sys.path

├── codeToTestPackage.py
└── somePackage
  ├── init.py
  └── moduleX
    ├── init.py
    └── someModule.py

boreal umbra
#

@delicate ermine you can have a setup.py file and use a virtual environment where the package is installed

#

as a side note, remember to use snake_case_instead_of_camel_case

delicate ermine
#

so I want to test out some new code and this will not be distributed to users

#

it will install locally inside that enviroment?

#

and then I can test?

strange sky
#

as a side note, remember to use snake_case_instead_of_camel_case
@boreal umbra why do python programmers prefer snake case, whilst pretty much every other lang uses camel case lol

flat gazelle
#

we took it from C

#

it is referenced in pep8 IIRC

#

most camel case langs take after java, since java is so popular

boreal umbra
#

@strange sky because other languages are ugly and camel case is a primary reason for that. Though if you need an objective reason, a study showed that snake-cased words are slightly faster to read.

strange sky
#

Ohh I see, thanks guys

boreal umbra
#

@delicate ermine sorry, I didn't know that you had replied. if you have a setup.py file and you pip install it with the -e flag, the project will always be available for that virtual environment

fast oxide
#

Question guys. I’m running my python project from the root directory and all the directory paths I’ve coded into my project are relative to the root directory. The problem I’m having is when I run tests in a sub directory (root-dir/tests) it errors out because the relative paths don’t work. Is their a way to change the relative path on my testing directory so it works with all the paths I’ve integrated into my project

feral cedar
#

because other languages are ugly and camel case is a primary reason for that. Though if you need an objective reason, a study showed that snake-cased words are slightly faster to read.
@boreal umbra do you have this study? sounds interesting lol

stable grail
#

I wonder if that study also takes into considderation that some languages concatinate words

muted crane
#

I never knew why camelcase syntax is so hated?

stable grail
#

like in english you write Bus driver while in norwegian you write busdriver

flat gazelle
#

I still feel like kebab-case-is-best

stable grail
#

so maybe the "how you read words" is dependant on your personal language preference

grave jolt
#

why not just

`allow spaces in identifiers`
stable grail
#

i think that would break keywords

grave jolt
#

If the identifier is enclosed in ` `, it's fine

stable grail
#

right, i thought that was a discord f-up

grave jolt
#

I think some language do that

flat gazelle
#

fortran lets you do that, kotlin too, cl too

stable grail
#

why dont you implement that and see how it works out?

grave jolt
#

sure

#

(not sure why that would be an issue -- other languages already do that)

stable grail
#

maybe because how englishthe syntax is

#

I think i mean grammar

grave jolt
#

If the identifier is enclosed within ` and `, there is no ambiguity

stable grail
#

but i would love to test a branch that has this implemented

grave jolt
#

oh, you mean, implement it in Python

stable grail
#

yes, share it, let me compile it and test it

#

i have changed the grammar of python before, its not very hard, it just a bit time consuming

grave jolt
#

Well, it will probably take me a whole week to find where the definition of NAME is located 😅

stable grail
#

no rush, but if you manage to do so, let me know 😄

desert peak
#

CTRL+F NAME

#

tf did these lemons come from anyways? I love using them, but they're weird.

stable grail
#

its because one of our owners is a lemon

#

and has a beard

#

so we make lemojis

muted crane
#

Wasn't lemon the original owner?

stable grail
#

nope

muted crane
#

Was it a team?

stable grail
#

there was joe and one more, the other one left and joe has been running it ever since with an increasing amount of staff.

#

also, off-topic.. so lets not continue here

unkempt rock
#

Can we put multiple image with tkinter using URL?

#

I tried but it seems to be working only for 1 image

grave jolt
#

Hm, changing the identifier rules might be a little bit more involved than a single line of code

#

just a little bit

radiant fulcrum
#

Nice

grand crag
#

Good to know it !

grave jolt
#

attempt 1 at adding `-ed identifiers, compiling... :pipenv:

grave jolt
#

seems to work

#

I will push to my fork now

stable grail
#

cool.. share the fork with me and ill compile and test it tomorrow 😄

#

aahh. thanks

#

will that overwrite my already existing cpython fork?

#

ill just grab the zip 😄

grave jolt
#

if you fork it, then yes, probably

#

you can just clone it to some other place

#

I should probably modify it so that the backticks aren't included in the name, i.e. `hello` is the same as hello

#

or maybe not

#

oh, I might just disallow backticked names without spaces

solar delta
#

Another question: whats the point of a controller class?

#

outside of mvc framework i dont see the abstraction purpose

cloud crypt
#

what’s the point of a controller class where

solar delta
#

Sorry outside of the mvc use case some people use it in abstract cases for example authorizationController or something

cloud crypt
#

this question sounds pretty Java

solar delta
#

yeah its a java styled language; Dart, im trying to implement it for data authorization meaning some users have authorization of group data sets

#

in python though ( i am building it a flask api for sharing customer data depending if they are in the group or not )

desert peak
#

this channel is to talk about Python the language

unkempt rock
#

what's going on at

#

line 6 and 7?

#

@boreal umbra help me out please 😢

raven ridge
#

They're assigning an attribute named store_name to the objects.

strong lantern
#

What is a pass? anybody

raven ridge
#

If you mean the Python pass statement, it's a statement that does nothing at all.

cloud crypt
#

^

desert peak
#

docstrings are preferable to a pass

#

as far as statements that do nothing

swift imp
#

Why dont dataclasses allow frozen fields

#

like for fricking sake

brave badger
#

@stuck imp Let's not dump GIFs on an on-topic channel

#

@swift imp To be fair though, dataclasses already imply immutability in some form, that being the entire dataclass being frozen

swift imp
#

Yeah but maybe I don't care about hashing and I want only want certain fields to be frozen

brave badger
#

As such, having one immutable field with other mutable ones is a bit off for me

swift imp
#

I dont see how its off, its like making a read-only property except you still get all the boiler plate reduction that dataclasses provide

#

I can get around it with a descriptor, its just lame to have to do it

brave badger
#

Fair enough

severe citrus
#

Is it possible to de-interpret python code ?

boreal umbra
#

@severe citrus as in, figure out what the source of pyc files was?

severe citrus
#

Something link how interpreter interpreted it ? what goes behind the see ?

#

like equivalent C/C++ code.

boreal umbra
#

It compiles to byte code and then interprets the byte code. Were you wanting to read the byte code?

severe citrus
#

Like I want to under stand. how below code is interpreted ?

#

my_list =[1,8,15]
g = (x for x in my_list if my_list.count(x)>0)

fresh cargo
#

Maybe dis.dis can help

raven ridge
#

!e ```
def f():
my_list =[1,8,15]
g = (x for x in my_list if my_list.count(x)>0)
import dis
dis.dis(f)

fallen slateBOT
#

@raven ridge :white_check_mark: Your eval job has completed with return code 0.

001 |   2           0 LOAD_CONST               1 (1)
002 |               2 LOAD_CONST               2 (8)
003 |               4 LOAD_CONST               3 (15)
004 |               6 BUILD_LIST               3
005 |               8 STORE_DEREF              0 (my_list)
006 | 
007 |   3          10 LOAD_CLOSURE             0 (my_list)
008 |              12 BUILD_TUPLE              1
009 |              14 LOAD_CONST               4 (<code object <genexpr> at 0x7f81fb83d2f0, file "<string>", line 3>)
010 |              16 LOAD_CONST               5 ('f.<locals>.<genexpr>')
011 |              18 MAKE_FUNCTION            8 (closure)
... (truncated - too many lines)

Full output: https://paste.pythondiscord.com/ejurexijed.txt

peak spoke
brave badger
grave jolt
#

will it run on Linux?

brave badger
#

will it run on Linux?
@grave jolt Hopefully™

true ridge
#

will it run on Linux?
@grave jolt AFAIK, yes. On all 3 major platforms

grave jolt
#

Windows 7, Windows 8, Windows 10

true ridge
#

Windows 7, Windows 8, Windows 10
@grave jolt oh, sorry for the confusion. I meant FreeBSD, OpenBSD and NetBSD

undone hare
#

Is the tweet about a dotNET Python implementation

peak spoke
#

Sounds like pyjion to me

sacred yew
#

@undone hare

swift imp
#

is there a way to tell copy.deepcopy to not copy certain objects? I'm having a little issue where something about pptx.enum.shapes.PP_PLACEHOLDER isn't deep copyable and its erking me

#

actually its pptx.enum.base.EnumValue

safe hedge
#

Hmm not entirely sure why that would cause an issue, the source code suggests it's just an int subclass

#

Maybe open a help thread and add the code/output you are getting

little plover
#

Guys. Anyone of You up to check an error in a 20-line code

#

actually 15

visual shadow
plain spindle
#

why does this typecheck?

from __future__ import annotations

from dataclasses import dataclass

from abc import ABCMeta
from typing import *

class User: pass
class Member: pass
class Guild: pass

class BaseEvent(metaclass=ABCMeta):
    ...

T = TypeVar('T', bound=BaseEvent)
TT = TypeVar('TT', bound=Type[BaseEvent])

Check = Callable[[T], bool]

class Message(BaseEvent):
    author: Union[User, Member]
    content: Optional[str]
    ...

class GuildLeave(BaseEvent):
    guild: Guild

HandlerCallback = Callable[[T], Awaitable[None]]

@dataclass
class EventHandler(Generic[TT]):
    checks: List[Check]
    callback: HandlerCallback[TT]

class Bot:
    def listen(self, t: TT) -> Callable[[HandlerCallback], EventHandler[TT]]:
        def deco(cb: HandlerCallback) -> EventHandler[TT]:
            self.add_listener(t, cb)
            return EventHandler(checks=[], callback=cb)
        return deco

    def add_listener(self, t: TT, cb: HandlerCallback) -> None: ...

bot = Bot()
@bot.listen(Message)
async def on_message(event: GuildLeave):  # expected this to error because the type of event must be Message
    pass
wide shuttle
#

What's doing the type checking? Are you using a static type checker?

#

Python does not enforce your type hints and annotations on any level by itself

brave badger
#

@plain spindle Checked on mypy, doing reveal_type(bot.listen(Message)) outputs this:

main.py:49: note: Revealed type is 'def (def (Any) -> typing.Awaitable[None]) -> main.EventHandler[def () -> main.Message]'
#

Bit of a shot in the dark but mypy's probably treating the call to add_listener as being passed a type variable instead of a concrete type

grave jolt
#

@plain spindle HandlerCallback is a generic type alias, why are you using it as a type hint directly?

unkempt rock
#

Can you code AI with python

#

does AI have another language and how do you write it

grave jolt
#

"AI" is a very broad term, what do you mean?

unkempt rock
#

like making tetris

#

its machine learning

grave jolt
unkempt rock
#

but what kind of lang does it use ?

grave jolt
#

there's no "language for machine learning"

#

If you want to do ML in Python, you use Python

broken palm
#

I think he means modules, but there is a huge difference between languages and modules 😂

grave jolt
#

@plain spindle

class Bot:
    def listen(self, t: TT) -> Callable[[HandlerCallback], EventHandler[TT]]:
        ...

^ this is not right if you want to pass the type of the event as the argument. Consider this:

def f(x: int) -> int:
    return x

f(int)

this is cleary wrong, right?

You have to do this:

class Bot:
    def listen(self, t: Type[TT]) -> Callable[[HandlerCallback], EventHandler[TT]]:
...

Another issue is that you're using HandlerCallaback, which is a generic type alias.
Why is the deco function even accepting a HandlerCallback? If it should accept the event type specified in the type variable, you should just do

class Bot:
    def listen(self, t: Type[TT]) -> Callable[[TT], EventHandler[TT]]:
        def deco(cb: TT) -> EventHandler[TT]:
            self.add_listener(t, cb)
            return EventHandler(checks=[], callback=cb)
        return deco
#

...also, you should make HandlerCallback generic on the T bound to BaseEvent, not TT bound to to Type[BaseEvent]

plain spindle
#

it's a decorator so it accepts a func

#

that's why it's accepting a HandlerCallback

#

the HandlerCallback, being an event handler, is what accepts the event type (T) when the event is dispatched, not the decorator

broken palm
#

What do you think about the future of Python and Swift, I am kinda excited to see where it goes

gaunt osprey
#

Is there something changing in Swift? I thought it's still an ios only language

#

I think python will still thrive in long term, but it won't be like an exponential growth and rather a steady growth. I've heard of people want to do datascience in swift but that was just speculation when i hear about it

deft pagoda
#

what do you think the best way for telling if a function is defined inside a class or not? this is one hack-y solution, but it's not entirely fool-proof: (given inside a decorator for context)

from collections import Counter
from functools import wraps
from inspect import signature

def run_n(n):
    """Decorator that allows a function or method to only run n times."""
    def deco(f):
        instance_run_counts = Counter()

        @wraps(f)
        def wrapper(*args, **kwargs):
            # determine if a function was defined in a class
            if (params := signature(f).parameters) and next(iter(params)) == 'self':
                if instance_run_counts[id(args[0])] < n:
                    instance_run_counts[id(args[0])] += 1
                    return f(*args, **kwargs)
            elif wrapper.nruns < n:
                wrapper.nruns += 1
                return f(*args, **kwargs)

        wrapper.nruns = 0
        return wrapper

    return deco
peak spoke
#

You don't really have much more information at the definition time

deft pagoda
#

probably true, i thought something might exist in inspect or similar that could tell

peak spoke
#

You could go through the frame but that's even hackier

unkempt rock
#

Anyone know the answer?

feral cedar
#

you

#

!rule 5

fallen slateBOT
#

5. Do not provide or request help on projects that may break laws, breach terms of services, be considered malicious or inappropriate. Do not help with ongoing exams. Do not provide or request solutions for graded assignments, although general guidance is okay.

unkempt rock
#

I have this function and I was wondering whether there was some way to return instead of print

def fib(n):
    for i in range(len(funclist := [])+n-1):
        (i==(n-2) and print(funclist[i-1]() + funclist[i-2]())) or funclist.append(lambda i=i:funclist[i-1]() + funclist[i-2]() if i>1 else 1)
feral cedar
#

does that actually work?

unkempt rock
#

feel free to try, but you need python3.8+ due to walrus

feral cedar
unkempt rock
#

thanks, will try there

weary minnow
#

this might be a silly question but could multi-threading / multi-processing be compared to quantum superposition

#

because if you think about it, if i wanted to display a progress bar while my program executed a function which it downloaded 5 different files

#

if i wanted to display only 1 progress bar

#

that would mean that the progressbar exists in 5 different states which constantly change every millisecond

#

so if you consider this

#
progress_bar = Bar(random_value)
time.sleep(0.01)
progress_bar.update() # makes a new random value
#

this would mean that a random bar for displaying the downloads is a feasible option

#

because essentially, it is switching between the progress of the 5 different downloads

#

which are all in different states

#

well not exactly superposition but it seems very similar

#

its just on a smaller scale

#

ps: for those who don't know what superposition is, its a certain object existing in different states at the same time

feral cedar
#

ehh...not exactly

weary minnow
#

@feral cedar well what do you disagree with?

feral cedar
#

sure, i agree, you could make the comparison and it does make sense

unkempt rock
#

Can somebody pm me and help me with something very easy?

weary minnow
#

lmaooo @feral cedar i know the question isn't directly related to python but i need a justification to place a random progress bar for my multiple downloads

feral cedar
#

why not just have 5 progress bars though

weary minnow
#

@feral cedar well thats the issue lol i can have that but its kinda broken because it keeps on glitching due to the values continuously changing on other states of the progress bar

#

its kinda hard to explain but its the the terminal doesn't know what to do lol

broken palm
#

@gaunt osprey you can now use python in Swift

cloud hamlet
#

What

boreal umbra
#

I noticed that numpy arrays doesn't support chained comparisons. I assume chained comparisons for native types have a special grammar?

undone hare
#

I remember reading the EBNF grammar, chained comparisons are weirdly parsed, but I do not know more about it

grave jolt
#

a == b == c is the same as a == b and b == c

#

Python doesn't know the types at parse time, so grammar doesn't affect that

undone hare
#

I'm not actually sure if it is interpreted like that

grave jolt
#

!e

import dis
def f():
    return a == b == c
dis.dis(f)
#
  3           0 LOAD_GLOBAL              0 (a)
              2 LOAD_GLOBAL              1 (b)
              4 DUP_TOP
              6 ROT_THREE
              8 COMPARE_OP               2 (==)
             10 JUMP_IF_FALSE_OR_POP    18
             12 LOAD_GLOBAL              2 (c)
             14 COMPARE_OP               2 (==)
             16 RETURN_VALUE
        >>   18 ROT_TWO
             20 POP_TOP
             22 RETURN_VALUE
undone hare
#

Was about to do that

grave jolt
#

well, the expressions are equivalent

undone hare
#

Hmm

grave jolt
#

the bytecode might differ

#

!e

import dis
def f():
    return a == b and b == c
dis.dis(f)
fallen slateBOT
#

@grave jolt :white_check_mark: Your eval job has completed with return code 0.

001 |   3           0 LOAD_GLOBAL              0 (a)
002 |               2 LOAD_GLOBAL              1 (b)
003 |               4 COMPARE_OP               2 (==)
004 |               6 JUMP_IF_FALSE_OR_POP    14
005 |               8 LOAD_GLOBAL              1 (b)
006 |              10 LOAD_GLOBAL              2 (c)
007 |              12 COMPARE_OP               2 (==)
008 |         >>   14 RETURN_VALUE
undone hare
#

Yeah, it seems to just be an optimized version

true ridge
#

I remember reading the EBNF grammar, chained comparisons are weirdly parsed, but I do not know more about it
@undone hare It is actually not much different than any separation (like x (',' x)*), the only thing that is different is the separator can be any of the comparison operators. Later on it is translated to AST as is (left is single value, and all comparators are in a list, and also all of the comparison operators).

#
comparison: expr (comp_op expr)*
a == a in b    
Module(
   body=[
      Expr(
         value=Compare(
            left=Name(id='a', ctx=Load()),
            ops=[
               Eq(),
               In()],
            comparators=[
               Name(id='a', ctx=Load()),
               Name(id='b', ctx=Load())]))],
   type_ignores=[])
undone hare
#

Very interesting, thanks!

clever shoal
#

Thank you for this

unkempt rock
#

What's the fastest threading?

reef egret
#

Anyone have some solid examples of a non-ORM based Repository Pattern in Python? I've got a MONSTER of an older Database.py lib that I want to move to a proper pattern based organization while I also switch over to asyncpg. Any guidance would be wondeful 🙂

boreal umbra
#

@reef egret so you're wanting to construct a wrapper around an old database?

reef egret
#

Not exactly - Just to rewrite my existing db lib setup I made (its a giant monolith of a python file)

boreal umbra
#

so what do you mean by "pattern" in this context?

reef egret
#

Repository Pattern is a design pattern

boreal umbra
#

in my experience, there's very little discussion of design patterns in the Python community.

reef egret
#

👍 gotcha

#

wasn't sure how much of that translated into Python

#

If you have say... an Animal and Person class that contained SQL statesments and operations specific to them - but you wanted them to share a DB instance - would you just send the DB instance in as a constructor param?

boreal umbra
#

There are a couple of "patterns" that I guess exist in Python. For example, I like to have class method constructors

reef egret
#

so you're not making a new connection for each of them essentially

boreal umbra
#

but I haven't heard people talk about "design patterns" for the high-level architecture of a project.

reef egret
#

interesting, Google produced a ton of results they were just all ORM based

boreal umbra
#

is that bad?

reef egret
#

nah I just cant use an ORM for speed reasons

boreal umbra
#

ah

reef egret
#

sure makes dev easier though heh

#

asyncpg is pretty sweet though

#

I'd been using psycopg2 until now

boreal umbra
#

I don't think I have anything else to contribute, but we do have a #databases channel. activity across the server will probably pick up in a few hours.

reef egret
#

sweet thanks @boreal umbra !

boreal umbra
reef egret
cloud crypt
tacit wing
#

@reef egret Wouldn't it just be easier to use SQL with python?

#

that's what I'm using atm

#

took like 5-10 mins to set up

#

shit nvm, didn't look into that link

#

lol

reef egret
#

Hehe

bronze acorn
#

Any idea on how I can save the configuration I made to my gui application that I made in python
So for example, this gui has theme setting which changes themes, the default theme is dark, if i changed it to white, i want when i close the program to save this configuration, so when i get back, it should be white, and so on for the rest of the settings

mint forge
#

not the channel?

bronze acorn
#

Sorry?

gleaming rover
#

Sorry?
@bronze acorn this channel is for discussion of the language

mint forge
#

@grizzled lichen not the correct channel for that

grizzled lichen
#

sorry im desperate no one replied to my help thing lol

#

do you however?

fossil pumice
fallen slateBOT
#

:incoming_envelope: :ok_hand: applied warning to @grizzled lichen.

muted crane
#

Oh, so now we warn people immediately? If they don't read the description or use the channel properly?

#

My main discussion here was about something really cool in python

#

It was about decorator syntax

#

It looks like there's more than one way to call decorator

#

For example there's the pie decorator syntax, pie decorator and space

#

List before def syntax

#

Why do we really have all this syntax when we could have only one?

brave badger
#

Could you list concrete examples of that?

#

Not really sure what you mean by these pie decorator syntax, pie decorator and space

muted crane
#
@classmethod
 def foo(arg1,arg2): 
...
#

This the pie syntax

#
[classmethod] 
def foo(arg1,arg2):
...
#

This is list before def syntax

#

There is also another variation where the list is after the function definition

brave badger
#

huh?

muted crane
#

It forms decorators like this

#
def foo(arg1, arg2) [ complicated(manyArgs=1, notTooUgly='yes'), even_more_complicated(42)]:
 ...
brave badger
#

I'm fairly certain that the latter one is not decorator syntax

muted crane
#

It is

brave badger
#

How exactly?

muted crane
#

Guido made it describing the extent of decorators

brave badger
#

Mind linking where?

muted crane
#

Here

brave badger
#

ah, I mean those are just proposals

muted crane
#

So they aren't really in the language?

brave badger
#

No

muted crane
#

And what do you think about them?

brave badger
muted crane
#

I see

#

Would you have them in the language?

#

Or how would you see it?

brave badger
#

This might just be because of my bias towards the proposal that survived but I do think that the @ syntax makes it clearer what you're actually doing with the function

muted crane
#

To be honest, the one that has a list after the function definition looks really cool

#

I guess it would give more freedom in declaring the decorator?

#

With the amount of arguments it gives of course

brave badger
#

Specifically, decorator application really is just

func = deco1(deco2(func))
```it perfectly makes sense for the decorators to be outside of the function, and to have them be signified by an `@`, which can be read as `apply`
muted crane
#

So that's why we chose the one which is commonly used today

brave badger
#

You could also consider the flexibility of it, considering that any valid Python expression can be a decorator

muted crane
#

For simplicity in reading the code

#

I guess using the @ syntax also makes it prettier to read , in comparison to the others

#

I should test on decorators and see how far it can expand with this syntax

brave badger
#

!pep 614

fallen slateBOT
#
**PEP 614 - Relaxing Grammar Restrictions On Decorators**
Status

Final

Python-Version

3.9

Created

10-Feb-2020

Type

Standards Track

brave badger
#

Here's a fairly recent one

sacred tinsel
#

the [] syntax feels really strange to me, how would that work in a repl?

#
>>> [1, 2, 3]
[1, 2, 3]
>>> def fn(): ...
... 
brave badger
#

The proposals state on both the @ syntax and the list syntax does break on the REPL, but it seems like the latter one does break harder

sacred tinsel
#

ah true, I guess the @ needs special treatment in the repl already

#

it needs to wait for what the next line will be

#

though @deco without a following def is invalid syntax, whereas the list isn't, so I guess that makes it "worse"

wide shuttle
#

I've read that compilation document on proposed decorator syntax before, but I'm so used to the current syntax that I can't really be objective anymore

#

Most of the alternatives just seem less readable and/or more verbose to me, especially those trying to force it on the def line or adding a level of identation

desert peak
#

we have enough indentation problems in python :x

#

I build web apps, lots of with: indents

#
with integration_conn:
  with db_conn:
    with db_crsr:
brazen jacinth
#
with A() as X, B() as Y, C() as Z:
    do_something()

fyi

desert peak
#

@brazen jacinth would that work when one of the latter statements relies on the previous?

#

I always forget you can compound with statements

radiant garden
#

I assume there's also code between each statement

desert peak
#

sometimes yes, sometimes no @radiant garden

brazen jacinth
#

if there's code with each statement, i don't really see a problem

#

indentation merely seperates blocks

#

if you need one with the scope of a context manager, i don't see why that is a problem

peak spoke
#

They create the exact same bytecode

desert peak
#

!e

import sqlite3

with sqlite3.Connection() as a, a.cursor() as c:
  print(a)
  print(c)
fallen slateBOT
#

You are not allowed to use that command here. Please use the #bot-commands channel instead.

peak spoke
#

Also got proper implicit line continuation in 3.9 for it

desert peak
#

mmm, my sqlite test is no good, it doesn't use a context manager

true ridge
#

Also, if you want to keep your code linear instead of separated across different blocks, you might want to give ExitStack a try.

desert peak
#

So I never noticed the Python logo is two snakes. That's clever.

stone crescent
#

Yea took me a while to notice as well

desert peak
#

!pep 638

fallen slateBOT
#
**PEP 638 - Syntactic Macros**
Status

Draft

Created

24-Sep-2020

Type

Standards Track

desert peak
#

Does anyone know what Macros would gain Python?

dusty mango
#

@desert peak i worry more confusing code

desert peak
#

well that's true of any feature, but my question is pointed.

grave jolt
#

@desert peak You mean, what advantages it might have?

desert peak
#

@grave jolt correct. what advantages does it give Python over its current state?

#

I read that it can enable features without being built into the language and that interests me a lot

grave jolt
#

yes, it's for trying out new syntax and semantics for features

#

for example, pattern matching

#

or 'do-notation' from haskell

#

the majority of people will probably hate your new favourite feature, but your personal project or your team might still benefit from it

desert peak
#

dreams of all the features

#

so basically it takes insert feature and generates python-valid code from the symbols to the macro?

#

like.. what macros do? lol

grave jolt
#

a macro is a function that runs at compile time

#

and it can transform the syntax tree

desert peak
#

hm, interesting. so would your source files always have a .pyc then?

grave jolt
#

what do you mean?

desert peak
#

well, just running a python script doesn't result in compilation

grave jolt
#

it does

#

how else would it run?

desert peak
#

I mean, a compiled file

grave jolt
#

Python source code is first compiled to bytecode, then that bytecode is executed

radiant fulcrum
#

its very common that your IDE will hide them from the file viewer

grave jolt
#

that bytecode may or may not be saved to a file

desert peak
#

where is logic that determines that? I don't ever see pyc files generated in my projects (though I do see __pycache__)

grave jolt
#

or 'do-notation' from haskell
when this:

do as result: 
    x := get_line
    y := get_line
    print_line("answer is:", x, y)
    pure(None)

is transformed to this:

result = get_line.flat_map(lambda x: get_line.flat_map(lambda y: print_line("answer is:", x, y).then(pure(None))))
desert peak
#

what is do notation, compiling a block to a single result?

grave jolt
#

"do-notation" allows you to write a chain like that in an imperative way

#

it's used in Haskell

desert peak
#

sounds like Rust's blocks

let result = {
  let x = get_line();
  let y = get_line();
  println!("the answer is: {} {}", x, y);
  None
};
grave jolt
#

no, that's a different thing

#

it's just building up a data structure

#

not performing all those operations

#

I guess do-notation is already implemented in some Rust crate

grand crag
#

I guess do-notation is already implemented in some Rust crate
wait there is this do-notation in some Rust crate ! Impressive 😂

grave jolt
#

I guess you can do something like

with do as result:
    do.x = get_line
    do.y = get_line
    do(print_line("answer is:", x, y))
    do(pure(None))
desert peak
#

interesting

grave jolt
#

oh, well, I've got an idea for a package ducky_devil

desert peak
#

that illustrates better for me

#

thanks

grand crag
#

oh, well, I've got an idea for a package ducky_devil
oh oh 😈

crude turret
#

in the shutil module, on linux specifically, shutil calls os.sendfile() for copying files, why do that when you could just do:

with open(file, "rb") as file:
    # write to new file
#

is it because they need a way to tell when the end of the file has been reached? i.e sent == 0

peak spoke
#

I'd guess that sendfile is more performant

crude turret
#

ah alright. ty

plain spindle
#

@deft pagoda if called as an instance method, the first argument will have a __func__ attribute pointing to the uninstantiated version. check if args[0].__func__ is f

#
🐍 class F:
••      def g(self):
••              pass
•• 
🐍 F().g.__func__
<function F.g at 0x7fca6637b3a0>
🐍 F().g.__func__ is F.g
True
#

caveat: this may be a CPython impl detail

muted crane
#

Please don't tell me I'm imagining a bunch of emoticons in your code

radiant garden
#

Just a custom repl skin

#

check out sys.ps1 and sys.ps2 ; )

#

export a script to PYTHONSTARTUP in your shell and enjoy

#

I personally have mine set to an ipython-like In [line]:

radiant garden
#

That being said... I wonder what's the wackiest repl prompt I could realistically work with.

unkempt rock
#

@grave jolt wouldn't it be this?

with result as do:
    do.x = get_line
    do.y = get_line
    do(print_line("answer is:", x, y))
    do(pure(None))
plain spindle
#

@radiant garden bruh i didn't even know about PYTHONSTARTUP

#

i just wrote a virtual env wrapper script which copies my sitecustomize.py file into every venv bigbrain

radiant garden
#

lol

flat gazelle
#

@viral flame @dark granite this is a discussion channel, for questions of this kind I would suggest #❓|how-to-get-help, this is not the proper channel.

grave jolt
#

@unkempt rock no, because do is the access point, and the resulting expression will be stored in result

#

actually, to make it threadsafe:

#
with do as result, h:
    h.x = get_line
    h.y = get_line
    h(print_line("answer is:", h.x, h.y))
    h(pure(None))
unkempt rock
#

why are sets left unordered when dicts are ordered?

#

it would make sense for them to have consistent behaviour right

radiant garden
#

I don't remember the rationale for making dicts ordered but one did exist and it was meaningful

flat gazelle
#

sets are optimized for fast in checks, and the current best way to do that is with using sets unordered

flat gazelle
#

dicts are ordered because it is an implementation detail of how they are written, and if it were not part of the spec, it would lead unportable code

wide shuttle
#

The reason is that sets work differently behind the scenes and it's not easy to make them remember insertion order while also keeping the flexibility of the set operations

sacred yew
#

idt the dict optimization applies to sets anyways

wide shuttle
#

Since sets, as a mathemacal construct, don't have an order, it's not a priority to make Python sets retain order

flat gazelle
#

since people would use dict ordering, and then it would not work outside cpython or when cpython decides to switch impls

wide shuttle
#

Although, arguably, I haven't followed later discussion on the topic in, say, the dev mailing list

#

Maybe there are some new plans now, but I wouldn't hold my breath, as sets being sets is the main priority

safe hedge
#

dicts are ordered because it is an implementation detail of how they are written, and if it were not part of the spec, it would lead unportable code
@flat gazelle That seems backwards. Like I'm not disputing this but I mean it feels wrong that python got a feature due to one particular implementation currently having that side-effect

flat gazelle
#

it is useful regardless, but it was orginally just an implementation that did not hold when keys get deleted

#

but it was easy enough to enforce

wide shuttle
#

It was introduced as an implementation detail in Python 3.6, with every warning that it wasn't a part of the specification

safe hedge
#

If users were opting to rely on a previously unenforced implementation side-effect that was on them surely

#

Again, I'm not complaining but it just seems a weird justification for adding as a feature

wide shuttle
#

Maybe, although it could also be considered a bit "tone deaf" if you break it in a few years now that is has been something that a lot of people started relying on

safe hedge
#

"A new implementation meant dicts were ordered, which some users started to rely on so now we are going to make it enforced"

flat gazelle
#

a language should not make it easy to do the wrong thing, and dict order made a lot of things much easier

wide shuttle
#

I think an earlier implementation even had deliberate scrambling of the order to prevent people from relying on that implementation detail

safe hedge
#

Surely that same logic could be used to justify making anything currently a CPython implementation detail the "standard"

wide shuttle
#

In part, although some things may be far more obscure and far less discussed than this implementation detail

safe hedge
#

a language should not make it easy to do the wrong thing, and dict order made a lot of things much easier
@flat gazelle Did people previously assume dicts were ordered? I feel like I learned very early dicts were unordered?

wide shuttle
#

The "why don't dictionaries retain order" has been a frequently asked question for a long time before 3.6 introduced it

flat gazelle
#

if you aren't sure, pop open a repl and check, and see that they are, you are not going to question it further

safe hedge
#

But there are lots of "why don't/doesn't..." questions which won't ever get changed

#

Just seemed a bit unnecessary to me and I do sort of find it more unintuitive for dicts/sets to have differing order behaviours than to have the same

wide shuttle
#

I think there was a point at which the decision was made that scrambling it on purpose just to not have that order show up was a bit weird as well. I think that was the decision that ultimately led to it being adapted into the language.

#

Dictionaries are so common and so many people really want their dictionaries to maintain order for some of their features, that once regular dicts did maintain order, people just started using it. And, at that point, you can go back and say "We told you it was an implementation detail" whenever it changes in the future (which could have been years from now), but I don't think that would have gone over well with a lot of users.

#

I agree that it's not a perfect reason, but it's a reason that makes sense once you're in the situation of having "remembering" dicts

safe hedge
#

I mean surely the answer to that is don't document it in the first place?

#

Like, if no-one mentioned they retained order even as an implementation detail would anyone have actually used it?

unkempt rock
#

ive never understood why people wanted dicts to be ordered anyways? its not like you can do dict[0] to pull out the first index

radiant garden
#

people will rely on the behavior regardless of documentation if it seems consistent

wide shuttle
#

It started to be discussed by a lot of people already, people who are intimately familiar with the implementation

safe hedge
#

people will rely on the behavior regardless of documentation if it seems consistent
@radiant garden Then people are dumb

peak spoke
#

It's nice to have and most major implementations did it anyway

wide shuttle
#

One of them even suggested in his Python talk something along the lines of "If you like this, like I do, just start using it! They can't change it then"

flat gazelle
#

that is a bad argument. You do not want magic behavior which is not actually guaranteed

#

programmers should not have to be smart to write python

safe hedge
#

I'm not sure who that is aimed at?