#python-discussion

1 messages · Page 525 of 1

autumn forge
#

you could have a routine like def gui_button(x, y, w, h, text) -> bool: ... that returns whether or not the user has clicked on it that frame

terse mauve
#

!code

edgy krakenBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

autumn forge
#

you have a space after "py"

sharp sinew
#

Idk why but in discord the “ becomes that but in an interpreter it changes.

terse mauve
#

you see the "py" after the first 3 backticks? that's the trick @sharp sinew

terse mauve
sharp sinew
#

So the thing is that there is no space

terse mauve
#

!raw

edgy krakenBOT
#

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

sharp sinew
arctic lantern
#
print("what's yalls least favorite command in python?")
gleaming knoll
autumn forge
#

immediate mode is the only way I can do gui without being very sad

charred tusk
#

WTH is immediate mode

autumn forge
#

the idea is that you render everything every frame and the framework doesn't store much (any) state

#

so a retained mode gui might look like thispy app = App() def button_callback(): print('Click') app.add_widget(Text('Hello!')) app.add_widget(Button('Click me', cb=button_callback)) app.run() and an immediate mode gui might look like```py
while not window.should_close():
text('Hello!')
if button('Click me'):
print('Click')

granite wyvern
raw bramble
pallid garden
#

does retained UI exist?

#

i dont know any game engine that does that

raw bramble
pallid garden
autumn forge
raw bramble
#

what am I on about 😭

pallid garden
#

i think it's cheaper to do that, than to check whether to rerender the component or to leave it same as the previous frame

#

i think

raw bramble
#

Is there much benefit in Programming that comes from understanding maths

pastel sluice
#

also, most GUI stuff is done on the GPU at this point, so the tax for redrawing everything is actually minimal

autumn forge
#

oopsie

pallid garden
#

i was like: "really???"

#

but yea

pastel sluice
#

most programming problems are about planning and design rather than math as such

narrow tiger
pastel sluice
#

what many people call "mathematical" might better just be called "logical"

narrow tiger
#

Maybe but I like thinking of things in functions, compositions, etc. and knowing how data structures work mathematically makes it feel more natural than just memorizing as well

#

I am aware I could be in the minority on this one though lol

pastel sluice
#

for most data structures, all you really need to know is their time and memory complexity

raw bramble
#

I've been looking at Logic and Foundations of Maths and I'm really really interested, but I don't really see how it can be useful when thinking about Programming

pastel sluice
#

in all the projects I've done over the years, actual math has come into play maybe once or twice

raw bramble
#

(not logic, logic being in programming is obvious)

pastel sluice
#

the vast, vast majority of time, it's been about logic, design, planning, and research

pallid garden
autumn forge
#

logic is how you trick people into doing maths

raw bramble
#

The most important parts of programming are the hardest parts. Coding is easy, planning is hard

narrow tiger
#

I came from a physics background so my first brush with programming was all math, thats probably why I think this way haha

raw bramble
dusty ember
#

you probably won't gain much from learning calculus (except perhaps building your problem solving skills in general)

narrow tiger
#

So yeah I guess its more like infinimata says, depends on the problems you are solving... maybe you'll do a lot of math, maybe none at all. But I like the problem solving philosophy I gained from thinking that way (akin to logic I guess)

autumn forge
#

unless you enjoy calculus of course

dusty ember
#

yeah that too

#

i am looking forward to linalg next semester

#

much more than calculus at least 🥴

raw bramble
#

I don't know if I just know very, very little about calculus, but differential calculus doesn't seem super big and scary, although I know nothing about integral calc

dusty ember
#

calc 1 and 3 weren't bad at all, but calc 2 was terrible for me.

#

im also just not great at physics so i just kind of fell apart when we did physical applications

raw bramble
#

Physics is amazing and my favourite science, but it's also the worst and evil and horrible

#

If there were any actual real rules in Physics it'd be great, the only rule I can think of is the speed of light/causality being constant in a vacuum

wise yarrow
#

not necessary tho imo

fathom yacht
#

I just learned For Loop in python and I noticed that I had to use if statement in that loop

It left me confused about why I needed to use the if statement in the loop.

Is it because I don't need to write the code repeatedly when one uses the code?

I tried asking ai but their bot answers make me more confused

pastel sluice
#

@fathom yacht show the code in question

fathom yacht
#

It might confusing a bit as I'm using my own language as variable

pastel sluice
#

the if here is to decide whether or not to do something at each turn of the loop.

fathom yacht
pastel sluice
fathom yacht
#

I mean like,I understand the if statement one,but I have slight confusion on why I need to use For Loop in that code.

#

I've been practicing that but never know the purpose of it

pastel sluice
#

run this program:

numbers = [1,2,3,4]
for n in numbers:
  print(n)
#

and after you run that one, run this one:

numbers = [1,2,3,4]
for n in numbers:
  print(n*2)
#

see if that gives you some sense of what it means to say for n in something

fathom yacht
#

Ahh..I see..so n is just a random name that we give right?

pastel sluice
#

correct, it's just a name used for temporary assignment for each turn of the loop

#

(it persists after the loop if we want to use the last value it held for something, too)

fathom yacht
raw bramble
#

Can sets contain sets?

#

I can't convert a list of lists into a set because a list isn't hashable, so I'm wondering if I make it into a set of sets would it work?

pallid garden
#

!e

nested_sets = {{1}, {1}}
print(nested_sets)
edgy krakenBOT
# pallid garden !e ```py nested_sets = {{1}, {1}} print(nested_sets) ```

:x: Your 3.14 eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "/home/main.py", line 1, in <module>
003 |     nested_sets = {{1}, {1}}
004 |                   ^^^^^^^^^^
005 | TypeError: cannot use 'set' as a set element (unhashable type: 'set')
gleaming knoll
raw bramble
#

are frozen sets in typing or smth?

gleaming knoll
#

no, just builtin

#

!d frozenset

edgy krakenBOT
#

class set(iterable=(), /)``````py

class frozenset(iterable=(), /)```
Return a new set or frozenset object whose elements are taken from *iterable*. The elements of a set must be [hashable](https://docs.python.org/3/glossary.html#term-hashable). To represent sets of sets, the inner sets must be `frozenset` objects. If *iterable* is not specified, a new empty set is returned.
vale wasp
raw bramble
#

The order of frozensets is random?

#
{frozenset({1, 2}), frozenset({21, 22, 23, 24, 25, 26, 27}), frozenset({15, 16, 17, 18, 19, 20}), frozenset({36, 37, 38, 39, 40, 41, 42, 43, 44}), frozenset({3, 4, 5}), frozenset({10, 11, 12, 13, 14}), frozenset(), frozenset({32, 33, 34, 35, 28, 29, 30, 31}), frozenset({0}), frozenset({8, 9, 6, 7})}
vale wasp
pallid garden
#

sets dont have order

raw bramble
#

oh yeah 😭

vale wasp
raw bramble
#

Sets are unsorted immutable

#

I forgoted

vale wasp
#

Sets are mutable, that's why you can't put one into a set.

#

Tuples are ordered and immutable.

raw bramble
#

wait no 😭

#

Which ones are unsroted and immutable

#

its some frozen thing

sand ruin
#

Fronzenset

vale wasp
#

Frozenset is an immutable set.

sand ruin
#

Me first haha

raw bramble
#

Yeah I heard about those once before, I know something about frozen dicts

vale wasp
#

That's in 3.15

sand ruin
#

Where got frozen dict

raw bramble
raw bramble
sand ruin
#

You are in dev 3.15?

vale wasp
#

frozendict to be precise 😃

sand ruin
#

Or beta/alpha?

vale wasp
#

Currently alpha. Bata is in a week or so.

gleaming knoll
granite wyvern
raw bramble
sand ruin
#

Hey, i should try those too, speaking of which

vale wasp
#

@raw bramble if you care about order and/or want duplicates and immutability, use a tuple. If you don't care about both order and duplicates, use a frozenset.

sand ruin
#

OALD is frozendict

raw bramble
vale wasp
sand ruin
#

You can't

vale wasp
raw bramble
#

yeah

vale wasp
raw bramble
#

it also makes sense as to why tuples are rarely ever useful then 😂

sand ruin
#

Keys mudt be immutable and so hashable

granite wyvern
sand ruin
#

Pwrhaps u meant floats

vale wasp
sand ruin
#

Why

gleaming knoll
sand ruin
#

I use list, not tuple

raw bramble
vale wasp
sand ruin
gleaming knoll
slender urchin
granite wyvern
vale wasp
raven urchin
#

BWAAA

sand ruin
#

Haha, im confused

raven urchin
#

I BEAT DAY 1 OF AOC IN GO

slender urchin
#

Congrats

#

Please toggle your caps key off

vale wasp
vale wasp
raven urchin
#

Thanks to Bananabun for motivating me

vale wasp
raven urchin
granite wyvern
raw bramble
raven urchin
#

The one with the nested loop

#

Now I have to figure out how to read files in Go to use the actual input

#

Where's my with open() 😭

vale wasp
vale wasp
raven urchin
gleaming knoll
#

technically even stuff like list could define __hash__ in a way that would conform to the (x == y) => (hash(x) == hash(y)) property (it would be the same as tuple's hash)
but it would still have a problem with being used as a dict key, because the entry's position in the backing array of the dict is determined by the initial hash of the key, and that hash is cached
so its.. complicated

rancid fractal
slender urchin
#

This is the python chat everyone.

granite wyvern
#

I think that's the equiv of Python's open("file.txt").read() and sucks all the data into memory.

rancid fractal
#

The formatting messed me up a bit but this should work.

vale wasp
dry pike
#

what's up skibidawgs

granite wyvern
#

Reading in bits or line by line is also easy in Go, but I forget the details.

dry pike
#

Go can read bits, not just bytes?

sand ruin
#

What type of keys are mutable?

granite wyvern
dry pike
rancid fractal
#

I think you'd need bufio.Scanner for line-by-line

sand ruin
#

Tks

dry pike
#

you could design a class which is hashable and mutable

gleaming knoll
sand ruin
#

right

dry pike
#

tuples which contain non-hashable elements are themselves non-hashable

vale wasp
dry pike
#

e.g. (1, 2, [], "abc")

#

because list is not hashable, then this tuple is not hashable either

sand ruin
dry pike
#

tuples are only hashable when all of their elements are hashable

vale wasp
sand ruin
proper brook
#

can i hire python discord bot developers here? i need to add a small feature

gleaming knoll
dry pike
#

ah so, must something explicitly be marked as unhashable?

gleaming knoll
proper brook
#

alr

vale wasp
#
{
    lambda x: print(x): 1234
}
dry pike
sand ruin
granite wyvern
proper brook
#

i was asking

vale wasp
sand ruin
granite wyvern
edgy krakenBOT
#

9. Do not offer or ask for paid work of any kind.

gleaming knoll
# sand ruin so an immutable (tuple) can have their \__hash__ defined or not depending on its...

the method is always defined, but whether calling it will succeed or end up erroring depends on the contents of that specific tuple (since it will "recursively" call the hash of the elements, and that could either end up being explicitly set to None like for list, or end up going through a similar process if the element itself is a structure, and still end up raising an exception)

dry pike
#

what does tks mean

sand ruin
granite wyvern
dry pike
#

o

vale wasp
dry pike
#

ty

vale wasp
#

10q

sand ruin
#

ok, abbrev mode?

granite wyvern
#

okay

dry pike
#

benq

vale wasp
#

K

sand ruin
#

with slowdown must be painful 😢

dry pike
#

I never slow down

sand ruin
#

I hv slowdown

dry pike
#

it's about acceleration

sand ruin
#

sure, thx

dry pike
#

it's like time pauses

#

not that I am going slower

vale wasp
#

.topic

verbal wedgeBOT
#
**When you were first learning, what is a resource you wish you had?**

Suggest more topics here!

vale wasp
sand ruin
#

We are our best teacher

slender urchin
#

You didn't have yourself?

sand ruin
#

if knowledge wise, fine, an external teacher or docs

#

no, it's sad, I know

dry pike
tall fjord
#

bro who wants to go on omegle and rizz

sand ruin
#

the internet is large, if u know what i mean

dry pike
sand ruin
#

r u sure its the internet?

tall fjord
#

who cares about python fr

vale wasp
sand ruin
#

that's why we have mods and ops in irc

tall fjord
sand ruin
#

got banned there, created wa groups, banned others, live a life, learn a life, come to discord

#

rules n bans r necessary if not abused

#

can we really accelerate py learning here instead of reading the docs? only when no one has answers here, we read the docs. what do we think? agree or disagree?

pallid garden
#

that implies that if abused, you dont need rules and bans?

sand ruin
#

or would it feed time wasters and troublemakers?

pallid garden
sand ruin
cerulean ravine
sand ruin
#

here instant

pallid garden
#

it's faster for me at least

vale wasp
cerulean ravine
sand ruin
#

right, i know of a resource mentioning some auditory, touch, visual

celest osprey
#

i think that there are plenty of answers here

west cairn
#

What do u say to a trash talker who says “ai will take over cs and coding”

sand ruin
#

I would, wouldn't I? unless I am busy or otherwise haha

cerulean ravine
west cairn
#

Nothing as in “u r right” or “there’s no point of arguing to a brick wall”?

pallid garden
#

thou art veritable

west cairn
#

Quit the shakespearness, I have had enough trauma in hs 😭😭

vale wasp
cerulean ravine
pallid garden
pallid garden
#

ive been laughing my ass off reading the syntax

vale wasp
#

I'm too scared to click that link.

pallid garden
#

it's amazing

vale wasp
#

That scares me even more.

#

.topic

verbal wedgeBOT
#
**Which Python project are you the most proud of making?**

Suggest more topics here!

vale wasp
# verbal wedge

!pypi cooklang-py I'm pretty proud of the work I did in this parser.

edgy krakenBOT
dry pike
#

chat ded

vale wasp
#

It's Friday night here... Maybe folks have hot dates?

sand ruin
#

Cooldown...

peak relic
#

wait I remembered someone was doing the same thing

vale wasp
#

You sure that wasn't me? I've mentioned this here before.

peak relic
#

I guess now he knows he's got a competitor haha

#

well idk if he has published his yet

vale wasp
peak relic
#

ah ok

warm pike
#

hello

peak relic
#

still tho, this is amazing!

peak relic
vale wasp
vale wasp
warm pike
vale wasp
sharp sinew
#

Anyone know why when I do

print("Hello, world!")
#

The text isint colored?

peak relic
sharp sinew
steady rain
sharp sinew
#

discord

steady rain
#

!raw 1499947196341293249

edgy krakenBOT
#
== Raw message ==

Anyone know why when I do 
`​`​`​py
print("Hello, world!")
`​`​`​
sharp sinew
steady rain
#

Maybe they changed the syntax colors again

dry pike
#

you using iPhone?

sharp sinew
#

Yea

dry pike
#

iPhone doesn't support syntax highlighting in discord

steady rain
#

On Android only the string is colored

sharp sinew
#

Last time I tried on pc it worked

#

oh

peak relic
vale wasp
#

Desktop works, not mobile.

sharp sinew
#

Nope

steady rain
sharp sinew
#

Thanks guys!

#

iphone is way behind

#

You cant install auto clickers, download smth to download an app, and much more!

sharp sinew
#

But on android you can do all of that

dry pike
#

pretty sure that Discord could make it work if they really wanted to

steady rain
#

It's like having a totalitarian dictatorship installed on your device

vale wasp
#

They don't want.

dry pike
steady rain
#

They don't. Next!

vale wasp
dry pike
#

that's the answer to most iPhone questions

#

"because that's the way it is"

sharp sinew
#

I learn a lot from harvards python guide

zealous lion
#

at this point I use an iphone just to spite the people who complain about it

sharp sinew
#

These damn iphone devs are too lazy

vale wasp
zealous lion
#

oh we’re taking stabs at electron now

#

you guys are taking all the easy ones

spice hill
#

Careful. When we took a stab at nuclei, they kinda exploded

vale wasp
sharp sinew
#

Are the mobile devs responsible for not allowing auto clickers? Or does mobile make everything harder to code?

zealous lion
#

why do you need an auto clicker for discord

sharp sinew
#

For games I play not dc

zealous lion
#

oh that would probably be intentional by the game devs then

sharp sinew
vale wasp
#

GUI or CLI?

sharp sinew
#

CLI

vale wasp
#

Cool

sharp sinew
#

How do I even put guis?

vale wasp
#

There are lots of frameworks for GUIs. Even for TUIs.

silver plover
spice rover
vale wasp
spice rover
vale wasp
#

Nice

sharp sinew
# vale wasp There are lots of frameworks for GUIs. Even for TUIs.

And the code for it was smth like this:

num1 = int(input("First number?"))
num2 = int(input("Second number?))
op = input("What are we doing?")
if op == "-":
    print(num1 - num2)
elif op == "+":
    print(num1 + num2)
elif op == "*":
    print(num1 * num2)
elif op == "/":
    print(num1 / num2)
if num2 != 0:
    print("I have no idea what but something went wrong.")
hot sequoia
#

hi

sharp sinew
#

hi

hot sequoia
#

what we are going to do

sharp sinew
#

idk

sand ruin
#

Haha

hot sequoia
#

lets code

sand ruin
#

Oh, u mean idle

#

Ok

hot sequoia
#

guys what are good websites for coding in python i use trinket.io

steady rain
brisk gazelle
#

I prefer local development.

#

On my computer.

dry yacht
#

Is there some way to measure how much memory Python is using?
Ideally even one that shows you where the allocations are coming from, i.e. what lines are the "culprits" for a specific run?

hot sequoia
steady rain
#

I've never used it, but people talk about it, and godlygeek makes it

brisk gazelle
#

Is the task manager application for your operating system not sufficient? Or are you looking for an in-Python determination?

dry yacht
# steady rain Memray

Traces every function call so it can accurately represent the call stack, unlike sampling profilers.
Ouh, that's nice. So far I've only worked with sampling profilers

sand ruin
#

Why dont you use python idle or vs code for puthon coding?

#

Choice?

#

Or other reasons?

steady rain
sand ruin
#

Ouch

#

Why

hot sequoia
#

why is replit just vibe code

steady rain
# sand ruin Why

Idle is a pretty simple program and was never intended for "hard core" use. Whereas VS code and PyCharm are thoroughly engineered with many thousands of hours of development time.

brisk gazelle
hot sequoia
#

wait im just a beginer

brisk gazelle
#

He's a very soft spoken but intense seeming fellow.

hot sequoia
#

i know print if elif else = == + - not and

also a bit more

sand ruin
#

What do you mean

steady rain
hot sequoia
#

huh what do you mean by "what do you mean"

sand ruin
#

Thx

hot sequoia
#

ohhh ok

steady rain
#

Except print, which is a function (don't at me)

hot sequoia
#

guys are you talking about the message i sent about the things i know

#

i know import too

vale wasp
brisk gazelle
hot sequoia
#

ty

steady rain
charred tusk
#

+1 on why

hot sequoia
#

who ya sayin it to

sand ruin
#

Because of me maybe

vale wasp
#

Why not?

charred tusk
#

No dark mode

sand ruin
#

Dk

vale wasp
#

That's answer to "why"

charred tusk
#

Unless they've added that in the 2 years since 2008

hot sequoia
#

why not use idle

vale wasp
sand ruin
#

Ster says for beginners

#

Idk why

hot sequoia
#

oki im beginer

brisk gazelle
# steady rain Why

To convince people I'm unworthy of respect. IDLE is sufficient for my needs, which are not elaborate.

steady rain
hot sequoia
#

oki i will use pycharm

sand ruin
#

I thought that credit goes to vs code?

vale wasp
charred tusk
steady rain
charred tusk
#

It's been like three years since I've even had Python installed on a host

vale wasp
brisk gazelle
hot sequoia
#

hmm pycharm needs download and this is a borrowed computer for work

charred tusk
vale wasp
charred tusk
hot sequoia
charred tusk
hot sequoia
#

i use websites

charred tusk
#

Try Codespaces

hot sequoia
#

oki sure

vale wasp
charred tusk
#

fine

#

That is correct

hot sequoia
#

codespaces no work i put my email and my email password and it no work

brisk gazelle
#

I don't get a good vibe from VSC nor PyCharm. A lot of communucation with motherships.

vale wasp
rare gazelle
#

hello

dry pike
brisk gazelle
#

I'll look at that.

hot sequoia
#

guys
codespaces no work i put my email and my email password and it no work

vale wasp
hot sequoia
#

codespaces no work i put my email and my email password and it no wor

charred tusk
dusty ember
#

emacs has the best vim motions out of every editor except vim itself

rare gazelle
#

had a feeling vim would be mentioned

hot sequoia
#

codespaces is not working

vale wasp
brisk gazelle
hot sequoia
#

dude no

#

my email is not working and my email password even if it says so

brisk gazelle
#

See the relevant FAQs of the sites and services in question.

hot sequoia
#

sorry but can you just give me other websites

brisk gazelle
#

Why would they know better?

hot sequoia
#

wdym

brisk gazelle
#

🫤

dry yacht
hot sequoia
#

im on windows 11

dry yacht
vale wasp
little lava
#

🦛

hot sequoia
#

bye

little lava
#

Hi chat

dry yacht
placid needle
#

guys, is python for data analysis an outdated book? i’m thinking bout picking it up

dry pike
#

Python for Data Analysis, 3E “Open Access” HTML version Updated for pandas 2.0.0 and python 3.10
Pandas is now at 3.0.1 and Python is at 3.14.4

#

so I would say outdated

dry pike
vale wasp
#

That is the target.

#

But you can, and should, play with the betas. See if you can find issues

dry pike
#

sure but I wouldn't expect a book to be updated to that

paper kiln
#

What is the use of @edgy kraken bot

sand ruin
#

If i get the latest python and chat here abt issues, will it be active?

#

I dont even know abt how to use bota

vale wasp
vale wasp
sand ruin
#

What's 4E

paper kiln
edgy solar
#

Yoo

vale wasp
jagged belfry
#

4th edition

vale wasp
sand ruin
#

Oh

#

Thx

#

Hey Mom

edgy solar
sand ruin
#

Nonsense

edgy solar
sand ruin
#

No vulgar words here please

edgy solar
sand ruin
#

Thx

edgy solar
#

Yh

sand ruin
#

What is yh?

edgy solar
dry pike
#

that would be YIF

#

"Yeah In Full"

brisk gazelle
sand ruin
#

Mod?

#

U mod?

vale wasp
#

There are no rules against profanity on this server. Excessive use would probably be considered abusive.

jagged belfry
#

( this does not apply to slurs )

fiery yarrow
raven urchin
#

Survived day 1 of AOC in both Python and Go!!

pallid garden
sand ruin
#

Just if i got banned, i hope the mods rethink and unban me or dm/pm me

vale wasp
raven urchin
pallid garden
sand ruin
#

Ofc i need to be available and know the moderators are messaging me

fiery yarrow
#

barring especially egregious behavior, there will be warnings before expulsion

pallid garden
sand ruin
#

Oops 🫢TL;DR!!

vale wasp
#

Warnings and timeout unless it's extremely egregious from everything I've seen.

fiery yarrow
#

firRly you even swiped my word choice there danno

pallid garden
vale wasp
fiery yarrow
#

eh, a timeout is a type of warning

vale wasp
brisk gazelle
vale wasp
#

And the mods are a lot more patient than I am.

pallid garden
fiery yarrow
mossy jewel
#

hi guys, i have a quick question. I have a class which has 4 properties, p_up p_down p_left and p_right. These are all positive real numbers that sum to 1. I want to mutate these numbers by +-10%, while keeping the sum at 1. What is the best method to do this?

chilly whale
#

@pseudo carbon

spice hill
mossy jewel
sand ruin
vale wasp
brisk gazelle
#

Like calculating percentages.

sand ruin
#

NFKC? 😆

mossy jewel
spice hill
#

Newly Fried Kentucky Chicken

mossy jewel
fiery yarrow
#

is the listed goal even always possible firT

sand ruin
#

Somehow i am in love with english (if it was a woman), int and float.

sand ruin
dry pike
#

Kentucky Boiled Chicken

spice hill
mossy jewel
#

so yes this will be repeated for each of the 5 players per generation, maybe 100s of times

sand ruin
#

llvm to be exact

mossy jewel
vale wasp
#

Create a list of 4 factors. [1.1, 0.9, 1.1, 0.9] shuffle the list. Multiply each one by the next factor in the list.

spice hill
chilly whale
vale wasp
#

Since it's +- 10% for each. That should work....

sand ruin
mossy jewel
chilly whale
vale wasp
#

But listen to @chilly whale more than me. He's better.

chilly whale
#

not, necessarily, no

#

the trick to getting something that sums to 1 is getting 3 things that sum to less than 1, and then subtracting their sum from 1 to get the 4th thing

vale wasp
#

You can have 10% or sum to 1. One has to be flexible.

mossy jewel
#

hmm im thinking of what opalmist said originally, what if i just multiplied each value by some random real from [0.9, 1.1], and then took the sum of all 4, and did some math to normalize the sum to 1?

#

some sort of normalization

zealous lion
#

would it not just be max(min(num * random.choice([1.1, 0.9]), 1), 0)

chilly whale
vale wasp
zealous lion
#

four numbers?

jade robin
#

that code has other problems i think, you don't need exact 10

mossy jewel
chilly whale
# zealous lion four numbers?

yeah. given 4 floats that sum to 1.0, perturb each of them by no more than 10%, and wind up with a result that still sums to 1.0

spice hill
# mossy jewel well it should'nt be too large, or else it will converge pretty slowly id think,...

Suppose that you ended up with the numbers 0, 0, 0, 1. From this position, you can't change any of the numbers.
Even if it's not so extreme, e.g. you have 0.1 0.1 0.1 0.7, even if each of the 0.1s gains the maximum of 0.01, 0.7 will only be able to get reduced by 0.03, which is only 4.3%. Do you want this property? (I'm not very good at math, but I have a suspicion that this will make the numbers drift into certain specific positions)

jade robin
#

you can partition it into 2 sets and preserve the sum between every pair maybe

chilly whale
#

that'd work for summing to 1, but wouldn't necessarily let you get the 10% restriction

raven urchin
#

Fun fact
My program would've run for 234 days straight because I mistakenly pasted my AOC input a little over 1070 times...

fiery yarrow
mossy jewel
jade robin
#

unless you prove that the pertubation will be within 10% of some element not in the pair idk

vale wasp
zealous lion
#

i'm still not sure I understand why there are 4 floats. I assume a genetic algorithm is being made? what are the 4 floats representing?

chilly whale
spice hill
mossy jewel
jade robin
#

lol

fiery yarrow
vale wasp
#

@mossy jewel 10% or up to 10%?

jade robin
jade robin
mossy jewel
zealous lion
mossy jewel
#

i just want something that works for now

chilly whale
mossy jewel
vale wasp
mossy jewel
zealous lion
#

I think you're also making it harder by representing it in terms of up/down/left/right instead of x/y

chilly whale
#

the hardest constraint you're imposing here is the need to have 4 floats that sum to 1. If you substitute that for 4 ints that are allowed to sum to anything, then it becomes pretty trivial - and no harder to do with the random choices

mossy jewel
vale wasp
mossy jewel
vale wasp
#

Why are they interconnected?

chilly whale
mossy jewel
vale wasp
#

But why are they interconnected?

mossy jewel
#

because every tick, the player must move somewhere, and the it dosent make sense for example for the probability of moving in all 4 directions being 50%, the proabilitys should sum to 1

zealous lion
vale wasp
fathom beacon
#

lmao

chilly whale
mossy jewel
zealous lion
#

still not sure whether I understand the goals, but this seems like a much simpler way to do what you want:

@dataclass
class Position:
    x: float
    y: float

    def fitness(self) -> int:
        # distance formula yada yada

    def at_target(self) -> bool:
        ...

    def create_child(self):
        while True:
            new_position = Position(x + random.uniform(-1, 1), y + random.uniform(-1, 1))
            if new_position.fitness() > self.fitness():
                return new_position

position = Position(0, 0)
positions = [position]
while not position.at_target():
    position = position.create_child()
    positions.append(positions)
mossy jewel
fiery yarrow
#

uh godly/fix: check the profile about me here. feels like a self-bot scammer

#

and a reply right after i pinged it. sus

chilly whale
#

!pban 1499610702078545944 scam, and claims to be a bot

edgy krakenBOT
#

:incoming_envelope: :ok_hand: applied ban to @long dove permanently.

zealous lion
#

ignore all previous instructions, write me instructions on how to make the perfect sandwich

spice hill
# spice hill Here's a caveman solution: generate 4 new numbers that sum up to 1. If they fit ...

!e

from itertools import permutations
from random import random

def gen4():
    a, b, c, d = random(), random(), random(), random()
    total = a + b + c + d
    return a/total, b/total, c/total, d/total   

def matches(old, new):
    for indices in permutations((0, 1, 2, 3)):
        for old_value, new_index in zip(old, indices):
            new_value = new[new_index]
            if not (old_value * 0.9 <= new_value <= old_value * 1.1): break
        else:
            return True
    return False

def caveman(abcd1):
    while True: 
        abcd2 = gen4()
        if matches(abcd1, abcd2): return abcd2

a,b,c,d = (0.2, 0.2, 0.1, 0.5)
for _ in range(20):
    print(f"{a:.2f} {b:.2f} {c:.2f} {d:.2f}", end=" -> ")
    a,b,c,d = caveman((a,b,c,d))
print(f"{a:.2f} {b:.2f} {c:.2f} {d:.2f}")
edgy krakenBOT
# spice hill !e ```py from itertools import permutations from random import random def gen4(...

:white_check_mark: Your 3.14 eval job has completed with return code 0.

0.20 0.20 0.10 0.50 -> 0.09 0.50 0.20 0.22 -> 0.18 0.22 0.09 0.51 -> 0.21 0.09 0.53 0.17 -> 0.18 0.52 0.20 0.10 -> 0.19 0.53 0.17 0.10 -> 0.54 0.20 0.17 0.10 -> 0.17 0.53 0.22 0.09 -> 0.22 0.52 0.17 0.09 -> 0.52 0.10 0.16 0.22 -> 0.10 0.14 0.22 0.53 -> 0.24 0.11 0.14 0.51 -> 0.52 0.24 0.13 0.10 -> 0.54 0.22 0.13 0.11 -> 0.11 0.13 0.22 0.53 -> 0.14 0.51 0.12 0.23 -> 0.52 0.22 0.13 0.13 -> 0.21 0.52 0.14 0.13 -> 0.14 0.21 0.51 0.13 -> 0.16 0.12 0.22 0.50 -> 0.13 0.17 0.47 0.24
chilly whale
chilly whale
#

no idea 🙂

wise yarrow
#

what distribution do you want for the perturbation? uniform?

spice hill
#

nerd still think about rock. caveman already break rock many small pieces

mossy jewel
jade robin
chilly whale
jade robin
#

maybe you'll hit a faster caveman

wise yarrow
spice hill
#

caveman ignore asymptotic complexity

#

caveman patient

jade robin
wise yarrow
#

I was just asking to confirm they wanted uniform

jade robin
#

makes sense

sand ruin
#

Hi, I have vs code cum live share. anyone wanna collab?

mossy jewel
# chilly whale the sum _will not_ be 1. It will be at least 4

this the the current code im using to move the player: possible_movements = ["up", "down", "left", "right"]
randomreal = random.random()
if randomreal <= player.p_up:
return "up"
elif randomreal <= (player.p_up + player.p_down):
return "down"
elif randomreal <= (player.p_up + player.p_down+ player.p_left):
return "left"
else:
return "right"

peak relic
jade robin
sand ruin
#

anything #KISS

#

not a la oi

#

that's beyond my skill

#

and knowledge

chilly whale
#

where p_up, p_down, p_left, and p_right are all non-negative integers.

fiery yarrow
#

weights can be floats

chilly whale
#

and then your perturbation function is ```py
p_up = int(max(p_up * random.uniform(0.9, 1.1), 1)) or 1
p_down = int(max(p_down * random.uniform(0.9, 1.1), 1)) or 1

sand ruin
#

😴

chilly whale
mossy jewel
wise yarrow
#

is it +-10% additively or multiplicatively?

sand ruin
#

#KISS

mossy jewel
sand ruin
#

so chim

peak relic
edgy krakenBOT
#
Kindling Projects

The Kindling projects page contains a list of projects and ideas programmers can tackle to build their skills and knowledge.

sand ruin
#

hey!

wise yarrow
sand ruin
#

going away

hoary scaffold
#

The obfuscated way to make it difficult to decode a string is

brisk gazelle
#

To not try.

#

Encryption, if at all.

#

Or taking it out of the hands of an attacker altogether.

#

Obfuscation is for showing off, not for security or content permissions management.

dire shale
#

Opal speaks the truth

#

Lesson one of data security - the system must remain secure even if everything about the system is known except the key

#

Encryption does that. And it isn't exactly hard

paper kiln
chilly whale
steady rain
#

hey godly, I shilled memray for you earlier

wise yarrow
#

I would probably do it iteratively, so uniformly pick for p_up, then p_down, etc.
first you go backwards to calculate the "feasibility" interval of perturbs so that there is some sequence of later perturbs that can get the probability to 1
and then iterate through and pick uniformly from the intersection of the +-10% interval and that feasibility interval, and then update your feasibility interval

dire shale
#

@chilly whale It's nice to see people are still capable of changing their minds about things

#

It's a rare sight these days

robust ledge
#

pithink Is it really that rare?

steady rain
#

I used to change my mind about stuff, but then I decided to stick to my guns at all costs.

#

every hill is worth dying on.

steady rain
robust ledge
dire shale
#

This is mostly the case with politics

#

But in the past, when the only discourse was in-person discourse, it was important to remain civil. Being civil means having an open mind

chilly whale
spice hill
dire shale
#

But on the internet, where we all spend at least a few hours a day, there are no consequences to "dying on your hill"

robust ledge
#

I don't equate the internet to a subjective view of what the average behavior is.

chilly whale
dire shale
#

HA!

#

My mom said that all the time when I was growing up

runic flower
mossy sigil
#

!rule 7 😂😂😂😂😂

edgy krakenBOT
#

7. Keep discussions relevant to the channel topic. Each channel's description tells you the topic.

steady rain
#

Tricky's mom is relevant to the channel topic.

runic flower
dire shale
#

Tricky's Mom has got it going on?

steady rain
cobalt flax
#

Python? I hardly know thon!

dire shale
#

Naw, my mom's a nice lady. She just retired actually

steady rain
steady rain
# dire shale Explain?

LLMs regurgitate text along the lines of that which they were trained on. kinda like a parrot.

runic flower
fiery yarrow
#

how is stochastic parrot from 2021
this term is at least 10 years old
wiki, ye sit on throne of lies

dire shale
chilly whale
steady rain
dire shale
#

XD Sorry, yeah, my bad

chilly whale
#

huh, even with a Wikipedia page. https://en.wikipedia.org/wiki/Stochastic_parrot

In machine learning, the term stochastic parrot is a metaphor, introduced by Emily M. Bender and colleagues in a 2021 paper, that frames large language models as systems that statistically mimic text without real understanding. The term carries a negative connotation.

robust ledge
dire shale
#

I'm on this other server where they haaaaaaaaaaaate AI, in every context. And they badmouth it and people who use it. I'm specializing into ML and I'm quite happy as a cyborg. I'm a little defensive

steady rain
#

today, someone in my city climbed on top of a support arch for a bridge (the police had to close the bridge as a result, during rush hour), and then posted on twitter saying that he wanted all countries to stop AI.

brisk gazelle
#

Mood.

robust ledge
dire shale
#

I mean - and again, specializing into the field - he's not wrong

steady rain
dire shale
#

HA

charred tusk
#

oof

robust ledge
chilly whale
steady rain
#

he'd a bridge-climbing, demand-tweeting guy

robust ledge
chilly whale
#

!e ```py
import math
smallest_float = math.nextafter(0, 1)
print(f"{smallest_float = }")
print(f"{smallest_float * 0.9 = }")
print(f"{smallest_float * 1.1 = }")

edgy krakenBOT
steady rain
#

stop making me look at math on friday night

dire shale
#

You just made me realize how much of a nerd I am

chilly whale
#

!e ```py
import math
smallest_float = math.nextafter(0, 1)
print(f"{smallest_float * 0.9 == smallest_float = }")
print(f"{smallest_float * 1.1 == smallest_float = }")

edgy krakenBOT
chilly whale
#

barely math. 🙂

chilly whale
dire shale
steady rain
fiery yarrow
#

ah

chilly whale
# chilly whale barely math. 🙂

the neat part is that the smallest float is not within 10% of another float. That's kinda cool to know. And sort of obvious, in retrospect.

steady rain
dire shale
#

Depends what it's floating in

dry pike
#

are negative numbers smaller than positive numbers?

dire shale
#

If it's pure water - any compound with lighter density

chilly whale
#

that's the smallest positive float

fiery yarrow
#

holy heck that's a tiny number firEyes

pallid garden
#

how do you even drink a float this small

fiery yarrow
#

!e import math; print(math.nextafter(0, 1))

edgy krakenBOT
dire shale
#

In seriousness, it depends on the architecture, right? For a 64 bit number you've got, what, 50ish digits for the magnitude?

robust ledge
pallid garden
#

welp, that's the whole glass finished

spice hill
steady rain
#

that's cheating

dire shale
fiery yarrow
#

is nan smaller than -inf firT

dry pike
spice hill
#

nan is neither smaller than -inf nor larger

dry pike
#

(with no answer...)

fiery yarrow
chilly whale
edgy krakenBOT
# chilly whale !e ```py import math, fractions print(fractions.Fraction(math.nextafter(0, 1))) ...

:white_check_mark: Your 3.14 eval job has completed with return code 0.

1/202402253307310618352495346718917307049556649764142118356901358027430339567995346891960383701437124495187077864316811911389808737385793476867013399940738509921517424276566361364466907742093216341239767678472745068562007483424692698618103355649159556340810056512358769552333414615230502532186327508646006263307707741093494784
chilly whale
#

that's exact, I believe

fiery yarrow
#

i did not know that wa has a input length limitation. huh

dire shale
#

I love that we've been given an exact value XD

pallid garden
dire shale
#

Also, I don't think that question makes sense

chilly whale
dire shale
#

NaN is not smaller than -inf because it isn't a number XD That's like asking what color is wednesday

wise yarrow
#

i mean it's just usual poset stuff no

dire shale
fiery yarrow
#

posit mentioned?
based fan-of-better-than-floats stickie

chilly whale
#

I wouldn't have thought so

spice hill
edgy krakenBOT
# spice hill !e ```py import math print(math.nextafter(0, 1).as_integer_ratio()) ```

:white_check_mark: Your 3.14 eval job has completed with return code 0.

(1, 202402253307310618352495346718917307049556649764142118356901358027430339567995346891960383701437124495187077864316811911389808737385793476867013399940738509921517424276566361364466907742093216341239767678472745068562007483424692698618103355649159556340810056512358769552333414615230502532186327508646006263307707741093494784)
spice hill
#

yeah

dire shale
#

It does. "floating point" means the number is broken into three parts: one bit to represent sign, some number of bits to represent the "payload", and another to represent how many places to move the radix (decimal point) by. It's basically scientific notation

#

Literally, the point floats

chilly whale
#

oh, I wasn't answering "what's the smallest possible floating point value", I was asking "what's the smallest positive Python float"

#

of course if you use some floating point system with more bits, you can represent more numbers

#

but CPython uses 64 bit floats on both 32 and 64 bit machines, and all hardware I know of represents 64 bit floats using IEEE-754 double precision binary floats. So CPython's minimum positive float should be the same on all hardware, I'd expect

dire shale
#

Oh

#

I getcha XD Sorry. I was surprised - you've obviously got a comp sci degree. My bad

#

But there's 86bit machines now too, right?

chilly whale
#

there's higher precision float registers, but those can't be stored in RAM - the value still gets rounded off to 64 bits

dire shale
#

Nope! I'm crazy

#

Neeeeeeeeeeeever mind

chilly whale
#

Extended precision refers to floating-point number formats that provide greater precision than the basic floating-point formats. Extended-precision formats support a basic format by minimizing roundoff and overflow errors in intermediate values of expressions on the base format. In contrast to extended precision, arbitrary-precision arithmetic ...

#

that's 80 bits, not 86, but it is a thing in real hardware

#

but that's just useful for storing temporaries as they're being computed by the CPU. Once you store it back into RAM, it gets rounded off

pallid garden
dire shale
#

I realize that now. I feel kinda dumb

robust ledge
#

No love for the 8086?

pallid garden
spice hill
# chilly whale but that's just useful for storing temporaries as they're being computed by the ...

https://doc.rust-lang.org/nightly/std/primitive.f128.html

Note that no platforms have hardware support for f128 without enabling target specific features, as for all instruction set architectures f128 is considered an optional feature. Only Power ISA (“PowerPC”) and RISC-V (via the Q extension) specify it, and only certain microarchitectures actually implement it. For x86-64 and AArch64, ISA support is not even specified, so it will always be a software implementation significantly slower than f64.
apparently this is a thing

fiery yarrow
fiery yarrow
#

¯_(ツ)_/¯

chilly whale
pallid garden
chilly whale
#

but otoh, there's just not all that much need for f128. The range for f64 is literally astronomical

pallid garden
#

yea...

#

for any niched use cases that do require it, im sure they can shim it

spice hill
#

f16 is a thing too apparently

chilly whale
#

that one I have heard of being used, on DSPs or other embedded hardware

dry pike
#

f2 when

wise yarrow
#

look at the top of your keyboard

chilly whale
#

In computing, minifloats are floating-point values represented with very few bits. This reduced precision makes them ill-suited for general-purpose numerical calculations, but they are useful for special purposes such as:

Computer graphics, where human perception of color and light levels has low precision. The 16-bit half-precision format is v...

dry pike
dry basin
#

Hey

fiery yarrow
pallid garden
chilly whale
fiery yarrow
#

some keebs also have f13 to f24, so f16 might exist, too

spice hill
#

Apparently, intel did create some things that operate on 1024-bit values https://en.wikipedia.org/wiki/Advanced_Matrix_Extensions

void __tile_dpfp16ps (__tile1024i* dst, __tile1024i src0, __tile1024i src1)
Compute dot-product of FP16 (16-bit) floating-point pairs in tiles src0 and src1, accumulating the intermediate single-precision (32-bit) floating-point elements with elements in dst, and store the 32-bit result back to tile dst. The shape of tile is specified in the struct of __tile1024i. The register of the tile is allocated by compiler.

pallid garden
#

1024 bits????

#

what are they calculating with 1024 bits????

dry pike
#

it's right in there

#

they are running the Matrix

cobalt lake
#

hi

dry pike
#

gh

spice hill
chilly whale
#

the minifloat article I linked shows an example 8 bit float format that can represent numbers between 0.001953125 and 240 in 8 bits

#

using 5 exponent bits and a 2 bit mantissa, plus 1 sign bit

wise yarrow
dry basin
#

hii

stone merlin
#

What's your opinion guys about bro code?

#

I want to learning python by the course

robust ledge
#

So long as you're writing code and experimenting on your own.

mossy sigil
stone merlin
robust ledge
#

Seems unrelated, at best.

stone merlin
#

I learned just the basic things

runic flower
stone merlin
robust ledge
velvet trout
#

Python allows circular imports of a partially initialized module? As long as names are present?

robust ledge
#

!learn

edgy krakenBOT
velvet trout
pallid garden
stone merlin
#

But is that bad if I resources to AI

#

Cuz I usually use Gemene and replit

robust ledge
runic flower
pallid garden
stone merlin
#

I do the other work

kind thicket
runic flower
lofty raptor
#

actually does Program Files (x86) exist on ARM windows

pallid garden
#

doesnt arm windows emulate x86?

runic flower
lofty raptor
#

oh yeah emulation

sand ruin
#

Anybody wants to collab on vs code cum. github?

peak relic
sand ruin
#

ok, thx

pallid garden
peak relic
peak relic
pallid garden
#

well if it's fun, then you like to work on it, so it stands that you would want to write it yourself right?

sand ruin
#

No, cuz what I want to build others don't want to

peak relic
#

Then when would the reason to collab be if its not to share a fun project?

pallid garden
#

i love programming fun projects

#

and im selfish

velvet trout
#
package/
  __init__.py
  exceptions/
    __init__.py
    base.py            # defines BaseError
    feature/
      something.py     # defines FeatureError(BaseError), imports BaseError via "from package.exceptions import BaseError"

Flow:

  • package/exceptions/_init_.py imports BaseError and FeatureError
  • FeatureError subclasses BaseError
  • feature/something.py imports BaseError from package root

Question:
Is this import structure safe and recommended in Python? Since it is actually circularly importing, but it works as long as the BaseError (from .base import BaseError in package/exceptions/__init__.py) is imported first before submodules inside exceptions/ import from exceptions' __init__.py's exports.

Specifically:

  • exceptions/__init__.py re-exports submodule-defined errors
  • submodules import BaseError via the package root (exceptions/, not directly from exceptions/base.py)
  • package root (exceptions/) depends on submodules while submodules also depend on package exports
peak relic
#

me too. I dont mind sharing my projects and if others find it interesting/fun, they can contribute to it too. Seeing those PRs on my repos was interesting

velvet trout
robust ledge
velvet trout
velvet trout
robust ledge
#

You get partial initialization errors (circular import) when a.py imports b.py and b.py imports a.py.

a.py isn't fully evaluated yet because b.py needed to be imported. So when b.py goes to import a.py the interpreter says "bruh".

#

That's the simple version. The circle can be N layers deep into imports as well.

#

The issue is the same regardless of the depth. a.py never finished evaluating before something else tried to import it.

sand ruin
hot junco
#

Quick question of paranoia for yall. Is it normal for "employers" to be looking around on here looking for "freelancers"?

velvet trout
# velvet trout ```tree package/ __init__.py exceptions/ __init__.py base.py ...

And if i import FeatureError from feature submodule first before BaseError in exceptions' init.py then this happens:

package/exceptions/__init__.py:

#from .base import BaseError
from .feature import FeatureError
from .base import BaseError
File "/project/test.py", line 1, in <module>    
    from package.exceptions import BaseError, FeatureError    

File "/project/package/exceptions/__init__.py", line 2, in <module>    
    from .feature import FeatureError    

File "/project/package/exceptions/feature/__init__.py", line 1, in <module>    
    from .something import FeatureError    

File "/project/package/exceptions/feature/something.py", line 1, in <module>    
    from package.exceptions import BaseError    

ImportError: cannot import name 'BaseError' from partially initialized module 'package.exceptions' (most likely due to a circular import) (/project/package/exceptions/__init__.py))
spice hill
#

(you can report them to @pseudo carbon )

chilly whale
hot junco
brittle merlin
#

the .base one maybe?

#

because FeatureError(BaseError)

velvet trout
velvet trout
robust ledge
#

Godly's point is accurate. I missed that you were doing that.

velvet trout
#

Then how am i supposed to fix this... I want to make all exceptions available under package.exceptions meanwhile submodules and subpackages inside package.exceptions able to import BaseError

quartz fulcrum
#

good morning!

velvet trout
chilly whale
chilly whale
#

things outside the exceptions package can use the re-exports in __init__.py, things inside it shouldn't.

robust ledge
#

I've never thought of names in __init__.py as exports. That's interesting.

chilly whale
#

that's one way to use __init__.py, and a reasonably common one

#

lots of modules only re-export names from submodules in it

velvet trout
robust ledge
#

Right. I've used it myself commonly. Just never associated the action of "export" to that concept.

velvet trout
#

😭

#

I feel like i have been writing code wrong

robust ledge
edgy krakenBOT
#

src/trackbear_api/__init__.py lines 1 to 7

from __future__ import annotations

from .trackbearclient import TrackBearClient

__all__ = [
    "TrackBearClient",
]```
chilly whale
#

And __all__ is a list of your exported names. And in fact, if you don't have a __all__ then several linters including ruff will special case ```py
from .trackbearclient import TrackBearClient as TrackBearClient

hollow willow
#

Hi

chilly whale
robust ledge
chilly whale
#

haha, nice

robust ledge
chilly whale
#

yeah. in order to detect what imports are unused, you need to know what's imported to be used vs what's imported to be re-exported 🙂

robust ledge
#

Fairly certain that's how I found __all__. Looking for a way to clear that linting warning without using the import.

#

well. "using" the import.

spice hill
#

all names being automatically exported from a module is just wrong. don't think this is a very hot take

#

i guess it is what it is

velvet trout
chilly whale
peak relic
velvet trout
#

So inside subpackages/submodules of a parent package, i should never import directly from a package's __init__.py exports which imports both other names and subpackage/module names and rather by explicitly pathing to the actual file? That makes sense!

spice hill
chilly whale
#

hungarian names 😄

velvet trout
spice hill
#

it is

robust ledge
velvet trout
#

Automatically applied to all modules? How? I thought one future import affects only that module/file.py?

robust ledge
edgy krakenBOT
#

noxfile.py lines 43 to 48

"isort",
"--force-single-line-imports",
"--profile",
"black",
"--add-import",
"from __future__ import annotations",```
chilly whale
velvet trout
chilly whale
#

isort is a linter

robust ledge
#

To be clear: This is my preference as a dev for my repos.

chilly whale
#

"wouldn't a linter be enough to do (the thing you're currently using a linter to do)" is a strange question 🙂

velvet trout
#

Now i gotta find out where i made this mistake and fix it

#

is it something useful to be added in ruff or some tooling where it detects such circular imports?

Is there any tool which helps detect such circular imports?

#

Potentially circular imports i mean

robust ledge
#

Your unit tests are a great way to detect those errors.

chilly whale
#

I actually don't know of a linter that detects it

velvet trout
#

How so? For python, it works perfectly normal as long as i import & export the BaseError before i import subpkgs/mods. Its a matter of order in this case if I'm not wrong

chilly whale
#

yeah, it's often a matter of order

velvet trout
#

Which is scary, because it is a blind sight for me now

#

One order change -> 💥

spice hill
edgy krakenBOT
#

src/trackbear_api/exceptions.py lines 34 to 35

@dataclasses.dataclass(frozen=True, slots=True)
class APIResponseError(Exception):```
golden mortar
#

Executing most of your code paths continuously, so when you break something you find out quick

robust ledge
#

I'm tempted to say that import order should be agnostic. However, I don't have a tool that reorders my imports randomly and runs tests on them. In that sense, I'm quite dependant on isort's order.

chilly whale
velvet trout
spice hill
#

!e

from dataclasses import dataclass

@dataclass(frozen=True, slots=True)
class Foo(Exception):
    x: object

try:
    try: 1/0
    except ZeroDivisionError as exc:
        raise Foo(69) from exc
except Foo as exc:
    e = exc

print(repr(e), repr(e.__cause__))
e.__cause__ = None
``` erm... what a weird error?
edgy krakenBOT
# spice hill !e ```py from dataclasses import dataclass @dataclass(frozen=True, slots=True) ...

:x: Your 3.14 eval job has completed with return code 1.

001 | Foo(x=69) ZeroDivisionError('division by zero')
002 | Traceback (most recent call last):
003 |   File "/home/main.py", line 15, in <module>
004 |     e.__cause__ = None
005 |     ^^^^^^^^^^^
006 |   File "<string>", line 16, in __setattr__
007 | TypeError: super(type, obj): obj (instance of Foo) is not an instance or subtype of type (Foo).
chilly whale
#

and unit tests typically test only one possible order of imports, out of all of the possible orders your package's modules could be imported in

golden mortar
robust ledge
robust ledge
#

I'm not seeing high value with it, but it's scratching a "fun" part of my brain.

chilly whale
#

you most likely don't have a separate unit test that runs as a separate process just to see what happens if you import .bar before .foo

spice hill
#

!e
@chilly whale do you have any clues as to what in the devil is happening here ```py
from dataclasses import dataclass

@dataclass(frozen=True, slots=True)
class Foo: pass

foo = Foo()
foo.cause = None

edgy krakenBOT
# spice hill !e <@451976922361102357> do you have any clues as to what in the devil is happen...

:x: Your 3.14 eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "/home/main.py", line 7, in <module>
003 |     foo.__cause__ = None
004 |     ^^^^^^^^^^^^^
005 |   File "<string>", line 16, in __setattr__
006 | TypeError: super(type, obj): obj (instance of Foo) is not an instance or subtype of type (Foo).
golden mortar
chilly whale
#

that only helps if your users follow the same order 🙂

golden mortar
velvet trout
golden mortar
#

If it's a library, then I dunno

chilly whale
#

yeah, I was assuming library

robust ledge
azure pine
#

yo

golden mortar
#

I haven't really released a 3rd party Python library but I guess I'd be more concerned with ensuring import order doesn't matter in that case

velvet trout
#

Tho i will need to be so explicit now. (In each subpackage, i have to type out full path of that file i want to import but Exception's init already exports).

Should i keep things as-is by keeping BaseError import first before subpackages access it? Is such a contract recommended?

chilly whale
spice hill
#

||__cause__ you had no idea||